Reputation: 81
In custom directive, pre link and post link functions are there. I have understood difference between pre and post but is there any use of post function if we are not going to use pre? Like why should we use post over link function.
Upvotes: 0
Views: 1264
Reputation: 629
Using the preLink()
and postLink()
functions within compile()
allows you more control over when the linking function is called.
link()
acts a shorthand for postLink()
.
In most cases, you would typically use link()
over postLink()
where all that is needed is basic DOM manipulation (very common). If, for example you needed to manipulate the model or $scope
before it is linked with the view, the preLink()
function is where you can do that.
It is worth noting though, that typically any issues that preLink
tries to solve can typically be resolved by a parent controller and should be encouraged.
Upvotes: 2