Currently, I have two directives and parent controller, all on some form.
I would like to implement "related field"-like functionality. That is, data from one directive should be passed to other preferably through controller so that I have full flexibility in "routing" data between fields.
So I have this set-up:
Controller:
$scope.$watch('form.model.object', function (newValue, oldValue) {
$scope.$broadcast("cmsRelatedChanged", {key: 'subcarriers', value: newValue['@identity']});
};
Second directive:
$scope.$on('cmsRelatedChanged', function(event, aditionalData) {
$scope.related[aditionalData.key] = aditionalData.value;
console.log("[CMSCollectionDirective] updated with: ", aditionalData, " event: ", event);
});
It do not work first time, when form is pre-populated with existing object But following changeds made in browser work.
As if second directive $on registered that listener after first $broadcast was made.
Additional info: Everything in second controller is done in link:, and second directive is also second in DOM.
Questions: How can I delay that first broadcast enough for $on to register listener?
EDIT: Added console.log("Adding listener") before $scope.$on, and it in fast is executed after first $broadcast, and that's why its not cough.