AngularJS directives attributes access from the controller

后端 未结 6 471
梦如初夏
梦如初夏 2021-01-31 15:31

I am trying to access the attributes of a directive in the controller function. However, by the time I access it, it is undefined. I noticed that if I do a simple timer it works

6条回答
  •  醉酒成梦
    2021-01-31 16:13

    What works is, if you set

    scope.text = $attrs.text;
    

    inside the linking and the controller functions. This will only work initially, as there is no 2way- databinding. You can use $attrs.observe though.

    See fiddle: http://jsfiddle.net/JohannesJo/nm3FL/2/

提交回复
热议问题