gpt4 book ai didi

javascript - Angular JS ng-change 事件没有启动

转载 作者:行者123 更新时间:2023-11-28 02:39:02 25 4
gpt4 key购买 nike

这是我的代码示例

<select ng-model="selectedProdTeam" 
ng-options="team for team in prodTeams | orderBy"
ng-change="getRolesBasedOnSelectedTeamProd()">
<option value="">Select Teams</option>
</select>

JS

$scope.getRolesBasedOnSelectedTeamProd = function(){
if($scope.selectedProdTeam != null || $scope.selectedProdTeam !=undefined){
$scope.prodRoles = $scope.prodResp.$scope.selectedProdTeam;
}
}

最佳答案

应该是,

<select ng-model="selectedProdTeam" ng-options="team for team in prodTeams | orderBy" ng-change="getRolesBasedOnSelectedTeamProd()">
<option value="">Select Teams</option>
</select>

编辑:

您的 orderBy 过滤器应采用参数或删除过滤器。

ex | orderBy:'name'"

演示

angular.module("myApp", [])
.controller("myCtrl", function ($scope) {
$scope.prodTeams = [
{ 'name':'Chelsea',
'id':1
},
{ 'name':'UK',
'id':2
}
];
$scope.getRolesBasedOnSelectedTeamProd = function(){
alert('fired');
}
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="myApp" ng-controller="myCtrl">
<select ng-model="selectedProdTeam" ng-options="team.name for team in prodTeams | orderBy:'name'" ng-change="getRolesBasedOnSelectedTeamProd()">
<option value="">Select Teams</option>
</select>
</body>

关于javascript - Angular JS ng-change 事件没有启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45469831/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com