0

I am still confuse where to use link and compile function.

Thanks in advance!

Azhar Syed
  • 35
  • 7

2 Answers2

0

From this SO Answer

compile function - use for template DOM manipulation (i.e., manipulation of tElement = template element), hence manipulations that apply to all DOM clones of the template associated with the directive.

link function - use for registering DOM listeners (i.e., $watch expressions on the instance scope) as well as instance DOM manipulation (i.e., manipulation of iElement = individual instance element).

Community
  • 1
  • 1
Shb
  • 802
  • 1
  • 14
  • 26
0

The link function is used in a directive.

The params of the link function reference the element the directive is attached to.

link: function(scope, element, attr)

Element here is the HTML element. and attr refers to the attributes of the HTML element

So you could do element.text('fred');

To set the text of the element to 'fred' and so on.

$compile I am not so familiar

halfer
  • 19,471
  • 17
  • 87
  • 173
danday74
  • 45,909
  • 39
  • 198
  • 245