AngularJS $watch vs $watchCollection: which is better for performance?

The $watchCollection() function is a sort-of mid-ground between the two $watch() configurations above. It’s more in-depth than the vanilla $watch() function; but, it’s not nearly as expensive as the deep-equality $watch() function. Like the $watch() function, the $watchCollection() works by comparing physical object references; however, unlike the $watch() function, the $watchCollection() goes one-level deep and performs an additional, shallow reference check of the top level items in the collection. … Read more

AngularJS ng-disabled directive with expression is not working

The ng-disabled expression is evaluated in the present scope. Hence, you should only need the following without any extra interpolation with {{..}}: Note that I added a ! since you probably want the button disabled if the user has not accepted the TnC. Working demo: http://plnkr.co/edit/95UiO4Rd2IMh8T1KjSQK?p=preview A comment was posted below asking how to reason about when to use {{…}} and when to use bare … Read more

AngularJS : Prevent error $digest already in progress when calling $scope.$apply()

Don’t use this pattern – This will end up causing more errors than it solves. Even though you think it fixed something, it didn’t. You can check if a $digest is already in progress by checking $scope.$$phase. $scope.$$phase will return “$digest” or “$apply” if a $digest or $apply is in progress. I believe the difference between these states is that $digest will process the watches of the current scope and … Read more