angularjs directive call function specified in attribute and pass an argument to it

后端 未结 7 744
难免孤独
难免孤独 2020-12-22 17:11

I want to create a directive that links to an attribute. The attribute specifies the function that should be called on the scope. But I also want to pass an argument to the

7条回答
  •  时光说笑
    2020-12-22 17:42

    Not knowing exactly what you want to do... but still here's a possible solution.

    Create a scope with a '&'-property in the local scope. It "provides a way to execute an expression in the context of the parent scope" (see the directive documentation for details).

    I also noticed that you used a shorthand linking function and shoved in object attributes in there. You can't do that. It is more clear (imho) to just return the directive-definition object. See my code below.

    Here's a code sample and a fiddle.

    Click me

提交回复
热议问题