1

I have taken a look at a couple other SO questions in regards to being able to use callbacks in directives but they don't seem to help with my fiddle. I have a parent directive and a child directive. On the scope of the parent I have a function that I need to invoke from a button on the child template directive. From what I have tried so far with my little Angular knowledge, I have not been able to get it to work without using ng-click on the button.

I have been told that a directive should not concern itself with knowing about other directives, instead exposing certain methods on its scope that can communicate with another directive depending on what is passed in to the directive. I could be off course here, and I think that my fiddle shows that.

Any help in understanding would be greatly appreciated.

pertrai1
  • 4,146
  • 11
  • 46
  • 71
  • Does this help? https://docs.angularjs.org/guide/directive#creating-a-directive-that-manipulates-the-dom – HarlemSquirrel Jun 11 '16 at 16:38
  • Just curious, why do you not want to use `ng-click`? – HarlemSquirrel Jun 11 '16 at 16:40
  • @HarlemSquirrel - I already have an event that I am invoking on `ng-click`. I tried multiple function invocations on the click and only the first one would fire. – pertrai1 Jun 11 '16 at 19:17
  • I don't understand what you mean with the multiple invocations. Can you please add it to the fiddle? I've updated your [fiddle](https://jsfiddle.net/awolf2904/5oqgt32r/2/) with a `ng-click`. Is it like you need it? It seems to work. – AWolf Jun 11 '16 at 21:32
  • @AWolf add that as answer so I can accept. thank you for updating the fiddlle – pertrai1 Jun 11 '16 at 23:57

2 Answers2

0

multiple function invocations on the click try this: you must have ; between functions

ng-click="myFunc1();myFunc2();myFunc3();"
avim101
  • 300
  • 1
  • 2
  • 9
0

To receive a callback function you can bind an scope with method = '&'.

If you need to expose a function of directive you can use a Service check it: How to expose behavior from a directive with isolated scope?

saulsluz
  • 94
  • 10