Michael
Michael

Reputation: 13616

Fire function when property value in the object changes

I have array of objects:

enter image description here

Each object has this properties:

enter image description here

I need to perform some operations when IsNormal property changes in one of the objects above.

I tried this:

   $scope.$watch('inspectionReviews.IsNormal', function () {
        //some logic
    })

But it doesn't work.

Any idea how I can trigger a function when IsNormal property of inspectionReviews object changes?

Upvotes: 0

Views: 71

Answers (1)

fos.alex
fos.alex

Reputation: 5627

You can make a deep watch or use watchCollection.

Deep watch:

 $scope.$watch('inspectionReviews', function (newVal, oldVal) { /*...*/ }, true);

watchCollection:

 $scope.$watchCollection('inspectionReviews', function (newVal, oldVal) { /*...*/ });

However, both of them will call the watch function for every change of the collection.

Upvotes: 1

Related Questions