What are Compile, Pre, and Post linking in AngularJS?
Answer Posted / chaitanya
Compile – This compiles an HTML string or DOM into a template and produces a template function, which can then be used to link scope and the template together. Use the compile function to change the original DOM (template element) before AngularJS creates an instance of it and before a scope is created.
Post-Link – This is executed after the child elements are linked. It is safe to do DOM transformation in the post-linking function. Use the post-link function to execute logic, knowing that all child elements have been compiled and all pre-link and post-link functions of child elements have been executed.
Pre-Link – This is 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. Use the pre-link function to implement logic that runs when AngularJS has already compiled the child elements, but before any of the child element's post-link functions have been called.
| Is This Answer Correct ? | 2 Yes | 0 No |
Post New Answer View All Answers
What is the difference between the $watch, $digest, and $ apply?
What are improvements in angular 6?
What is the use of bearer token?
Explain $q service, deferred and promises.
What is difference between javascript and angular?
How would you control size of an element on resize of the window in a component?
Is rxjs the same as react?
Can react be used with php?
How do you share data between controllers in angularjs?
What do you know about uppercase filter and lowercase filter in angularjs?
How to bind selection box with options in the angular js?
Indexof(), if the given value is not in the string / array it will return what?
Can you automate porting angular 1 code to angular 2?
What is angular and why angular?
How $location is different from window.location in angularjs?