Answer the question
In order to leave comments, you need to log in
What is better to use to communicate directive and controller?
Hello.
There is a huge directive (consists of models, services, subdirectives and controllers) that is created for a specific project. You need to create an interaction between the directive and the page controller. What options do I see:
Through the service of the directive and callback of the controller
Through the callback of the controller and scope : { callback : '&' } directives
Through the $emit() events
Through $watch (but I don’t even consider this, as for me it’s a bad option)
Directive will work with images. The page controller will store an array of images, which, when the directive is activated, will be transferred to it through the directive service. Further, the directive will work with images, so I would like to know how best to respond to this work.
Answer the question
In order to leave comments, you need to log in
broadcast?
// directive
scope.$broadcast('updateOrder');
//ctrl
$scope.$on('updateOrder', function(ev, args) { console.log('ok') });
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question