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
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.