Calling directive's methods from parent controller in AngularJS

后端 未结 5 1118
无人及你
无人及你 2021-02-03 22:59

I am using AngularJS with the alias controllers pattern. I can\'t access (or I don\'t know how to) directive methods from a parent controller.

I have a

5条回答
  •  梦如初夏
    2021-02-03 23:46

    I have another solution, that lets you use isolate scope and don't rely on broadcast. In javascript methods can be used like variables, co you can simply pass the method you want to the directive.

    so in html:

    
    

    and in directive

    scope: {
       text: '=',
       changeText: '='
     }
    

    Here is slightly modyfied codepen, where You can see what i have in mind.

提交回复
热议问题