angularjs - How to watch an object property? -


i want have attribute directive can used this:

<div my-dir="{items:m.items, type:'0'}"></div> 

in directive can turn object like:

function (scope, element, attributes, modelcontroller) {    var ops = $.extend({}, scope.$eval(attributes.mydir)); } 

now m.items array. , somewhere down line ajax call replaces array new one. i'd watch this.

how can watch m.items or whatever typed in items property in attribute? should watch expression be?

you should able use scope.$watch watch attribute. angular invoke callback entire object when of values change.

function(scope, elem, attrs) {   scope.$watch(attrs.mydir, function(val) {     // new value, val.   }, true); } 

http://plnkr.co/edit/jbgqw8ufzh1ej1ppq3ft

anytime model changes (by typing in input) directive updates elements html in $watch.

edited answer: want include true last argument compare object values, not references. otherwise run digest more 10 times , exception.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -