admin管理员组文章数量:1421750
Is it possible to know the elements old value and new value when it is changed dynamically?
An example, I have a button with value 190
<button name="btn1" directiveX>190</button>
And this button will be changed dynamically by socket.io. When its changed, I need to pare these values, if the new value higher then the old value is.
Thank You!
Is it possible to know the elements old value and new value when it is changed dynamically?
An example, I have a button with value 190
<button name="btn1" directiveX>190</button>
And this button will be changed dynamically by socket.io. When its changed, I need to pare these values, if the new value higher then the old value is.
Thank You!
Share Improve this question asked Oct 22, 2012 at 13:20 VuralVural 8,74611 gold badges42 silver badges58 bronze badges1 Answer
Reset to default 6If you $watch
the value in your scope, it will give you the old value and the new value. So your link function in the directive would look like this
link: function(scope, element, attrs) {
scope.$watch("foo", function(newVal, oldVal) {
//logic based on oldVal
}
}
And then in your HTML
<button name="btn1" directiveX>{{foo}}</button>
See http://docs.angularjs/api/ng.$rootScope.Scope
本文标签:
版权声明:本文标题:javascript - Is it possible to know the old value of an element within the directive in AngularJS? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745354404a2654964.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论