I have a button with the ng-disable directive attached and a function to evaluate the button state. When the view loads, I notice that the function is called around 6-8 times. I
ng-show
will be evaluated on every digest cycle - it doesn't know (at that level of abstraction) what is checked inside ng-show
, so must reevaluate anytime the result could have changed. What you may want to do is something like:
$scope.canDelete = checkIfCanDelete();
checkIfCanDelete = function() {
//your check
$scope.canDelete = Site.selected && Site.selected.children.length;
}
$scope.$watch('Site.selected', function() {
checkIfCanDelete();
}
But honestly, if it's not computationally intensive (and this isn't), it's probably easier and clearer to just leave it as it.