2017-08-02 67 views
2

這裏是我的代碼示例角JS NG-change事件沒有啓動起來

<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; 
    } 
} 
+1

您的HTML一個錯字。 select元素缺少'>'。 –

+0

對不起......它是在發佈時在stackoverflow –

+0

其實,甚至沒有射擊。 –

回答

0

它應該是,

<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'" 

DEMO

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>

+0

請忽略錯字。它發生在發佈到堆棧溢出 –

+0

有一個實際問題。 –

+0

你的orderby應該帶一個參數。檢查編輯 – Sajeetharan

相關問題