I have an array that looks like 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 any change to the 'isInvalid
' attribute inside 'options
', I want to trigger a function that would evaluate the entire array and set some properties to 'true
' and some to 'false
'.
I understand something of this sort can be done using deep $watch object equivalence, but I am not sure as to how exactly I can watch only for change in the 'isInvalid
' and not change in lets say 'optId
'.
In the bigger scheme of things, my intent is to validate the entire array by a set of business rules. So, if the "isInvalid
" attribute of the first object changes to 'true
', I want to make sure that the 'isInvalid
' of the second object is set to 'false
' and so on.
So if there is a better way to do this other than $watch
, I am all ears, because I'm relatively new to Angular and I'm a little lost!