加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 使用Angular js处理Select2事件

发布时间:2020-12-17 07:54:32 所属栏目:安全 来源:网络整理
导读:我在使用Angular js激活我的select2 on-change事件时遇到了问题. 这是我的HTML: select ui-select2="{allowClear:true}" data-placeholder="Select a Department" ng-change="DoSomething()" class="input-max" ng-model="l.DepartmentID" option value=""/
我在使用Angular js激活我的select2 on-change事件时遇到了问题.

这是我的HTML:

<select ui-select2="{allowClear:true}" data-placeholder="Select a Department" ng-change="DoSomething()" class="input-max" ng-model="l.DepartmentID">
    <option value=""></option>
    <option ng-repeat="d in l.LineLookups.Departments" value="{{d.DepartmentID}}">{{d.Type}}</option> </select>

当选择下拉列表更改时,更改事件不会触发.这是我的控制器中的事件处理程序:

$scope.DoSomething = function () {
        alert('here');
        ...
}

处理这个问题的最佳方法是什么?我被告知要对模型值进行监视.这会有用,还是有更好的方法?

另外通过观看ng-model:

在视图中:

<select ui-select2="{allowClear:true}" data-placeholder="Select a Department" class="input-max" ng-model="l.DepartmentID">
<option value=""></option>
<option ng-repeat="d in l.LineLookups.Departments" value="{{d.DepartmentID}}">{{d.Type}}</option>
</select>

在控制器中:

$scope.$watch('l.DepartmentID',function (newVal,oldVal) {
    if (oldVal == newVal) return;
    alert('here');
},true);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读