Angularjs:听来更改指令模拟 [英] Angularjs: Listen to model change in a directive
本文介绍了Angularjs:听来更改指令模拟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图找出我怎么能听的时候模型是指令中更新。
I'm trying to find out how I can listen to when the model is updated within an directive.
eventEditor.directive('myAmount',function(){
return {
restrict: 'A',
link: function(scope, elem, attrs) {
scope.$watch(attr['ngModel'], function (v) {
console.log('value changed, new value is: ' + v);
});
}
}
}
};
});
该指令是NG重复内称为
The directive is called within ng-repeat as
<div ng-repeat="ticket in tickets">
<input my-amount ng-model="ticket.price"></input>
</div>
很高兴的任何帮助。我不明白scope属性怎么看起来像一个NG重复之内。
Very happy for any help. I don't understand how the scope attribute looks like within an ng-repeat.
感谢。
推荐答案
http://jsbin.com/mihupo/1/edit
ATTRS
而不是 ATTR
app.directive('myAmount',function(){
return {
restrict: 'A',
link: function(scope, elem, attrs) {
scope.$watch(attrs['ngModel'], function (v) {
console.log('value changed, new value is: ' + v);
});
}
} ;
}
);
这篇关于Angularjs:听来更改指令模拟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文