AngularJS trick

You’re using AngularJS with some form and don’t want to hassle with event listeners when changing a property of an object. Usually, the ng-change directive works only with the new value of whatever you toss at it, but you can send the old value as well.

Simply add curly brackets to the parameter and it’ll send a copy of the old untouched data.

The function declaration of setChangedStatus looks like this:

This might be helpful, if you need to compare a number of other properties in the car object and need to respond to that.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.