如何从jquery触发ng-change? [英] How to trigger ng-change from jquery?
本文介绍了如何从jquery触发ng-change?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个选择标签,如下所示:
I have a select tag as follows:
<select ng-change="doSomething()" ng-model="myModel"> </select>
,并且我正在使用它的jQueryUI控件(组合框),从jQuery触发的事件更改"不会触发doSomething().
and I'm using a jQueryUI control for it (combobox), the event "change" triggered from jQuery doesn't trigger doSomething().
您知道如何从外部角度触发ng-change吗?
Do you know how to trigger ng-change from outside angular?
推荐答案
糟糕-这是很糟糕的做法-但是您可以使用angular.element
并从位于目标控制器内的元素中获取scope
.
Ugh - this is terrible practice - but you can use angular.element
and get the scope
from an element that resides within the target controller.
示例:
<div ng-controller="myApp">
<span id="test"></span>
</div>
Javascript:
Javascript:
var scope = angular.element("#test").scope();
scope.doSomething();
您的scope
变量现在可以访问在myApp
控制器上定义的所有方法.
Your scope
variable now has access to all the methods defined on the myApp
controller.
这篇关于如何从jquery触发ng-change?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文