What is the difference between a link and compile in angular?



What is the difference between a link and compile in angular?..

Answer / Chitra Gautam

In Angular, a link function is responsible for compiling the HTML template and creating a scope for the directive. The compiled directive is then returned and added to the DOM by the link function. On the other hand, compile refers to the process of converting an AngularJS expression or template into executable JavaScript.n```htmln<my-directive></my-directive>n// Link functionnfunction link(scope, element, attrs) {n // Compile functionnvar compiled = $compile(template)(scope);n // Append the compiled HTML to the elementnelement.append(compiled);n}

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More AngularJS Interview Questions

How many modules can be used in a single html page?

1 Answers  


Explain currency filter and when to use it?

1 Answers  


How to bind to user input events to component event handlers?

1 Answers  


What is a typescript decorator?

1 Answers  


How are angularjs prefixes $ and $$ used?

1 Answers  


Which one is fast between $digest and $apply?

1 Answers   SLK Software,


Differentiate between dom and bom.

1 Answers  


What are different states of a form in AngularJS?

1 Answers  


How to do custom form validation in AngularJS?

1 Answers  


How to read data from the server?

1 Answers  


Is primefaces free?

1 Answers  


What are services in javascript?

1 Answers  


Categories