A
A
Alexander Evgenievich2015-06-24 17:17:39
JavaScript
Alexander Evgenievich, 2015-06-24 17:17:39

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

2 answer(s)
M
Maxim Kuznetsov, 2015-06-24
@NewProject1

broadcast?

// directive
scope.$broadcast('updateOrder');
//ctrl
$scope.$on('updateOrder', function(ev, args) { console.log('ok') });

_
_ _, 2015-06-24
@AMar4enko

Via controller callback and scope : { callback : '&' } directives

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question