Two things to note:
- Scopes inherit from each other prototypically and form a tree. Scopes have a reference to $parent which can be used to traverse.
- A digest cycle is something that happens on a scope object. Ie.
$scope.$digest()
. This runs a digest on the scope, and then recursively does the same for all of the child scopes. $scope.$apply()
is like doing $rootScope.$digest()
. Since it starts at the root, it calls a digest on every other scope. So $apply
might be excessive.
To answer your question, scope.$parent.$digest()
will trigger a digest on scope
's parent.
But it seems that the triggering of the digest isn't actually your problem. $apply
will trigger digests on all scopes, so if that isn't working for you, I don't think your problem is simply that you need a digest to be triggered.
Perhaps you don't need the whole directive to re-render, but just need a part of it to update? If so, consider data binding to some shared service like this.
HTML
<div ng-app='app'>
<one></one>
<two></two>
</div>
JS
angular
.module('app', [])
.directive('one', function() {
return {
restrict: 'E',
scope: {},
template: "<input ng-model='shared.val'> {{ shared.val }}",
controller: function($scope, Shared) {
$scope.shared = Shared;
}
};
})
.directive('two', function() {
return {
restrict: 'E',
scope: {},
template: '<p> {{ shared.val }}</p>',
controller: function($scope, Shared) {
$scope.shared = Shared;
}
};
})
.factory('Shared', function() {
return {
val: ''
};
});