I know "&"
binding used to pass the method (expressions) to directives isolate scope, so the directive will able to execute it when needed.
Many times I need to "pass" the same expression from my main controller, more than one level deep, to nested directive (2-3 levels). This why on my own, I don't like to use "&"
for that purpose. For me, sending "callbacks" using "="
bindings works much better. But this is not a question.
The question is:
What for, I can use "&"
in addition to passing functions?
Can I have something like this: my-directive-click="clickCount +=1"
?
In reality, the
&
is meant as one-way-data-binding.So
=
is two-way-data-binding which means changes done on the directive will persist to the original object.@
is just a string.And
&
is special. The thing is that it creates a getter for your value, in the case of an invoked function, the getter actually calls the function. I tend to do this on the DDO:So in this way, the value bound to the
scope
isgetParameters
(so it's clear is a getter) but on the directive element you will only refer it asparams
:Your question is vague though and even though you may be able to do what you were asking, I think it would be best to do that inside the directive rather than the way you proposed.
I hope this helped.