From the course: AngularJS 1.x Tips and Tricks

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Functions: angular.equals and angular.toJson

Functions: angular.equals and angular.toJson - Angular Tutorial

From the course: AngularJS 1.x Tips and Tricks

Start my 1-month free trial

Functions: angular.equals and angular.toJson

- [Instructor] Why does Angular implement it's own angular.toJson function when JavaScript already comes with the JSON.stringify function? Why isn't angular.equals always the same as other equal utilities? For example, low dashes is equal. I face these questions when I first started using Angular. Taking care to note the difference has helped me avoid some pitfalls along the way, and understand Angular a little bit better. Angular tends to prefix it's own properties and functions using the dollar sign. For example, ng-resource has methods such as $save. Scope has $apply, $watch, et cetera, and the ng-model controller has $error and similar properties. Because of that, the Angular team implemented .equals so that it ignores properties that start with the dollar sign. This means it is possible to compare objects without fear of Angular's properties getting in the way. For example, when comparing two instances of ng-resource objects. Equals also differs from other utilities in that it…

Contents