选择二事件有角的js处理 [英] Select2 event handling with Angular js

查看:98
本文介绍了选择二事件有角的js处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有让我选择2平变化事件采用了棱角分明的js火的问题。

I'm having an issue getting my select2 on-change event to fire using Angular js.

下面是我的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>

在选择下拉的变化,变化不会触发事件。下面是在我的控制器我的事件处理程序:

When the select dropdown changes, the change event doesn't fire. Here's my event handler in my controller:

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

什么是处理这个问题的最好方法?有人告诉我设置的手表型号值。请问这项工作,或是否有更好的办法?

What's the best way to handle this? I've been told to set a watch on the model value. Will that work, or is there a better way?

推荐答案

通过观看NG-模式备选:

Alternative by watching 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);

这篇关于选择二事件有角的js处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆