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


Please Help Members By Posting Answers For Below Questions

Is angular or react easier to learn?

386


How to update angular 4,5, 6 to angular 7?

441


Explain ng-bind and ng-bind-html directives.

462


What is a good use case for ngrx/store?

460


What is the difference between ‘this’ vs $scope in angularjs controllers?

435






What is scope hierarchy in angularjs?

443


What is the scope in angularjs?

464


What are the differences between $resource and $http?

437


What is service factory?

368


What is angularjs prefixes $ and $$?

430


How to redirect to 404 or other path if the path does not exist in angular 2?

453


What is the use of @inject()?

447


How to get user input from the $event object?

466


Why we use ng app in angularjs?

405


Why is jit so fast?

427