The compile
function of angularjs' directive has two functions: preLink
and postLink
.
Pre-linking function
Executed before the child elements are linked. Not safe to do DOM transformation since the compiler linking function will fail to locate the correct elements for linking.
Post-linking function
Executed after the child elements are linked. It is safe to do DOM transformation in the post-linking function.
It tells what we should not do in preLink
, I wonder what and when should I use preLink
? For most of time I just used postLink
. Is there any case that we must use it?