Preventing redundant parsing
The $parse operation can often be unnecessarily repetitive in certain situations. If your application scales to the point where this redundancy is starting to become a performance factor, then the parsing can be refactored in order to prevent reparsing the same expression over and over.
Getting ready
Suppose that your application resembles the following code:
(index.html)
<div ng-app="myApp">
<div ng-controller="OuterCtrl">
<div ng-repeat="player in data.playerIds"
ng-controller="InnerCtrl">
</div>
</div>
</div>
(app.js)
angular.module('myApp', [])
.controller('OuterCtrl', function($scope, $log) {
$scope.data = {
playerIds: [1,2,3]
};
})
.controller('InnerCtrl', function($scope, $log, $parse) {
$scope.myExp = function() {
$log.log('Expression evaluated');
return 'watchedValue';
};
$scope.$watch(
...