So I have two directives (Timeline and Displayer) instanciated in a controller.
When a click happens on Timeline, it $emits a TimelineClicked event to the controller .
The controller $on('TimelineClicked', cb), $broadcasts an UpdateDisplay event to Displayer .
I have two situations here :
onUpdateDisplaycan be called during a$digestcycle, for example, on load, which updates UI- but when it comes from
TimelineClickedapparently it is not$digested.
Hence wrapping the method with $apply like so:
$scope.onUpdateDisplay = function($event, activeObjects) {
$scope.$apply(function() {
//$scope values modification
});
};
Will trigger an $apply already in progress error when in situation 1 and not it 2 .
I don't consider doing something like if ($scope.$root.$$phase != '$apply' && $scope.$root.$$phase != '$digest') which is way too dirty IMHO.
- How should two directives talk together and make sure their scope is always up-to-date?
- Does the $apply cycle waits for events callbacks to finish?
- Should I wrap the
applysomewhere else (around the$on('TimelineClicked', cb))?
I have tried several configuration without success...