Can the child region $ be applied without using the parent

Is it possible for a child $scope (isolated or not) to execute $scope.$apply without applying a patent scope?

Expensive calculation happens in the parent area (it's hard to cache), and I don't need angular to run the calculation again.

eg:

 <div ng-controller="ParentController"> {{ expensiveFunction() }} <div directive> <h1 ng-click="applyChildScopeOnly()">Click {{ value }}</h1> </div> <div directive> <h1 ng-click="applyChildScopeOnly()">Click {{ value }}</h1> </div> <button ng-click="applyChildrenScope()"/> <!-- apply to children scope only --> </div> 

Directive:

 module.directive('directive', ['$document','$rootScope', function ($document,$rootScope) { return{ restrict:'AE', scope:{}, link:function($scope, element, attrs){ $scope.applyChildScopeOnly = function(){ $scope.$apply(); // don't apply changes to $parent scope }; } } }]); 
+6
source share
1 answer

You can call $scope.$digest() instead of $scope.$apply() to re-evaluate the clock in the current area and all of its children. Calling $scope.$digest() will not evaluate the clock on any parent objects.

As a side note, $scope.$apply() calls $rootScope.$digest() backstage.

Further information here: http://docs.angularjs.org/api/ng . $ rootScope.Scope

+7
source

All Articles