I have this simple scenario:
值由jQuery的val()方法更改的输入元素.
我正在try 使用jQuery设置的值更新Angular 模型.我试着写一条简单的指令,但它不是我想要的.
以下是指令:
var myApp = angular.module('myApp', []);
myApp.directive('testChange', function() {
return function(scope, element, attrs) {
element.bind('change', function() {
console.log('value changed');
})
}
})
这是jQuery部分:
$(function(){
$('button').click(function(){
$('input').val('xxx');
})
})
和html:
<div ng-app="myApp">
<div ng-controller="MyCtrl">
<input test-change ng-model="foo" />
<span>{{foo}}</span>
</div>
</div>
<button>clickme</button>
Here is the fiddle with my try:
http://jsfiddle.net/U3pVM/743/
有人能给我指个方向吗?