AngularJS directives attributes access from the controller

后端 未结 6 563
梦如初夏
梦如初夏 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:10

    The link function is called before the $digest loop, at that moment scope variables are undefined. Look at this chapter and this other to understand how the link function operates. You only use the link function to define watches and/or behaviors for the directive, not to manipulate the model, this is done in controllers.

提交回复
热议问题