AngularJS Directive Callback

前端 未结 2 1638
无人及你
无人及你 2020-12-14 18:30

I would like to send a call back into a directive via a parameter on the tag, and then call that method when appropriate inside the directive. For example, when a button was

相关标签:
2条回答
  • 2020-12-14 19:08

    Tricky tricky angular, when declaring the argument in the HTML, it needs to use snake case, instead of camelcase to match.

    Works:

    <hello-world on-load-callback="myCallback(arg1)"></hello-world>
    

    Doesn't Work:

    <hello-world onLoadCallback="myCallback(arg1)"></hello-world>
    
    0 讨论(0)
  • 2020-12-14 19:18

    Also the callback needs to be:

    scope.onLoadCallback({arg1: 'wtf'});
    

    The named parameters are then bound to the corresponding parameters used in the callback attribute (not all need to be used).

    0 讨论(0)
提交回复
热议问题