角度变化不起作用

时间:2016-04-24 16:03:37

标签: angularjs html-select

我有一个选择下拉角js和新角度js。 代码是:

<select class="required_input_mandatory inputs" ng-options="o.ID as o.OrganizationName for o in OrganizationModel track by o.ID" ng-model="OrganizationOption" ng-change="GetUsers()">
   <option value="">-Select-</option>
</select>

当表单处于编辑模式时,HTML标记为

<select class="required_input_mandatory inputs ng-valid ng-not-empty ng-dirty ng-valid-parse ng-touched" ng-options="o.ID as o.OrganizationName for o in OrganizationModel track by o.ID" ng-model="OrganizationOption" ng-change="GetUsers()">
<option value="" class="" >-Select-</option>
<option label="SHUK" value="1" selected="selected">SHUK</option>
<option label="SHAU" value="2">Cowshed</option>
<option label="SHNA" value="3">SHNA</option>
<option label="SHEUR" value="4">SHEUR</option>
</select>

和GetUsers:

$scope.GetUsers = function() { 
    var uid = $scope.OrganizationOption; 
    var getUser = NotificationSettingsController.GetUserByOrganization(uid);    
    getUser.then(function (pl) { $scope.SourceUser = pl.data; }, function (errorPl) {
        console.log('Some Error in Getting Records.' + errorPl);
    }); 
} 

选项“SHUK”被选中。现在,在更改为其他值时,将调用GetUsers()函数,但下拉列表中的选项将恢复并选择“-Select-”选项。

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

HTML代码from here

<select class="required_input_mandatory inputs" ng-options="o.ID as o.OrganizationName for o in OrganizationModel track by o.ID" ng-model="OrganizationOption" ng-change="GetUsers(o)">
   <option value="">-Select-</option>
</select>

JS代码:

$scope.GetUsers = function(orgOption) { 
    var uid = orgOption; 
    var getUser = NotificationSettingsController.GetUserByOrganization(uid); 
    getUser.then(function (pl) { 
        $scope.SourceUser = pl.data; 
    }, 
    function (errorPl) { 
        console.log('Some Error in Getting Records.' + errorPl); }); 
    });
}