简体   繁体   中英

Angular Directive Callback Function

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.

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

ng-click="myFunc1();myFunc2();myFunc3();"

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM