angularjs - How to watch for change in one particular nested array item attribute in Angular JS? -
i have array looks this:
$rootscope.array = [{ "id":"a", "title":"a", "options":[ { "optid":"abc", "isinvalid":false }, { "optid":"efg", "isinvalid":false } ] }, { "id":"b", "title":"b", "options":[ { "optid":"hij", "isinvalid":false }, { "optid":"lmn", "isinvalid":false } ] }]; on alter 'isinvalid' attribute within 'options', want trigger function evaluate entire array , set properties 'true' , 'false'.
i understand of sort can done using deep $watch object equivalence, not sure how can watch alter in 'isinvalid' , not alter in lets 'optid'.
in bigger scheme of things, intent validate entire array set of business rules. so, if "isinvalid" attribute of first object changes 'true', want create sure 'isinvalid' of sec object set 'false' , on.
so if there improve way other $watch, ears, because i'm relatively new angular , i'm little lost!
if construction not big, deep watch trick.
http://teropa.info/blog/2014/01/26/the-three-watch-depths-of-angularjs.html
if concerned performance, , depending scenario, evaluate doing like:
having parent/global isinvalid flag, whenever flag marked invalid mark global invalid, have watch global invalid flag , 1 time flag invalid traverse find not valid element.
other options come mind add together watch per entry in array, not sure if have worse performance deepwatch solution.
if don't create deepwatch abuse, can solution scenario.
angularjs watch deep
No comments:
Post a Comment