角度js ng-change不起作用

Posted

技术标签:

【中文标题】角度js ng-change不起作用【英文标题】:angular js ng-change not working 【发布时间】:2016-08-17 23:00:45 【问题描述】:

我有一个选择下拉角 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-”选项。

我该如何解决这个问题?

【问题讨论】:

可以加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); ); 【参考方案1】:

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); ); 
    );

【讨论】:

以上是关于角度js ng-change不起作用的主要内容,如果未能解决你的问题,请参考以下文章

Angular 11,js在角度路由后不起作用

使用UI-Bootstrap 0.11.0,角度js中的活动选项卡不起作用

使用 Angular js 验证 jquery 下拉插件不起作用

三.js SpotLight 急性光束不起作用

角度简单路由不起作用

分页在角度 7 中不起作用。(我使用角度材料)