Really Sorry about the extremely late response to this thread.
Olivier, originally you had recommended using events ($on / $broadcast) and
in the new update yo have mentioned using $watch based on evolved
understanding of Angular. Please would it be possible to elaborate why the
$watch would be preferable to events i.e. any performance or hidden issues
with events?
Unfortunately Angular Directives don't have a "delegation" model where a
parent controller can delegate/command a child directive to do something,
with the guarantee that it will get done. All the currently available
approaches are like a "best effort" where it is really up to the directive
to do something, or not.
Assuming a parent has to notify a directive of a change in the data, and
the directive needs to update its view. Using $watch on a scope property in
the directive seems hacky as $watch or $watchCollection can sometimes
become inefficient if the watched property is a deeply nested array.
One could create a separate "eventCounter" and keep incrementing it each
time a new update is to be triggered & watch it in the directive, but again
it doesn't feel like the right way to do it. I was of the opinion that
events are the "best" way to achieve this, hence would appreciate your
feedback on the above question.
On Monday, May 27, 2013 at 4:44:23 AM UTC+5:30, Olivier Clément wrote:
>
> Hi
> I don't remember quite well as it been a while indeed;
>
> Also, I must say my comprehension and understanding of angular has evolved
> since too.
>
> If you need to apply a different set of effects by clicking different
> buttons for instance, maybe you could just use $scope.$watch from within
> the directive, and binding the effects you get from the server to a scope
> property on that same directive.
>
> Basically you could have <directive ng-model="whatever"
> effects="effectList">
>
> effectList being a property in you controller's scope or something. In the
> directive you'd need to define this property to its scope: { effects: "="}
>
> Hope this help!
>
> Le 2013-05-26 à 17:46, Corentin Kerisit <[email protected]
> <javascript:>> a écrit :
>
> Hello Olivier,
>
> I know its been a while since you had that issue but I would really love
> to hear how you managed to control the directive from the controller.
> I am facing such issue with a directive embeding a Three.js canvas. I have
> a listing of effects off a webservice. I need to apply these effects to the
> canvas on ng-click.
>
> I was thinking of the $on/$broadcast. Is that what you used in the end ?
>
> Thanks
>
> On Monday, November 5, 2012 7:44:54 PM UTC+1, Olivier Clément wrote:
>>
>> Sorry for the late response;
>>
>> Thank you all for your inputs; I thought about using a Service, but
>> considering I won't ever need more than one instance of that particular
>> directive at a time, I think it might be a bit overkill to create a service
>> for this;
>>
>> I guess that the solution that would suits my needs the best would be
>> Witold's suggestion of using $on/$broadcast
>>
>> I'll get into this right now;
>>
>> --
>>
>> As for more details:
>>
>> The directive is a D3.js Tree that display's an organisation.
>> Outside of that directive I have a few controls that will modify the tree
>> accordingly. I need to be able, on the click of a button or similar
>> (outside the directive, under the same parent controller), to fire a
>> function living in the directive and pass some parameters to it. That
>> function will take a list of nodeID as params, and the directive will be
>> responsible of getting JSON from a WebService and inject this data in the
>> tree
>>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "AngularJS" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/angular/htKUVVNhi7A/unsubscribe?hl=en-US
> .
> To unsubscribe from this group and all its topics, send an email to
> [email protected] <javascript:>.
> To post to this group, send email to [email protected] <javascript:>
> .
> Visit this group at http://groups.google.com/group/angular?hl=en-US.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
>
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.