So I have two directives (Timeline and Displayer) instanciated in a controller.
When a click happens on Timeline, it $emit
s a TimelineClicked
event to the controller .
The controller $on('TimelineClicked', cb)
, $broadcast
s an UpdateDisplay
event to Displayer .
I have two situations here :
onUpdateDisplay
can be called during a$digest
cycle, for example, on load, which updates UI- but when it comes from
TimelineClicked
apparently it is not$digest
ed.
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
apply
somewhere else (around the$on('TimelineClicked', cb)
)?
I have tried several configuration without success...