Eusebiu Schipor Let’s talk tech!

  • After we’ve declared the link function in our directive we have to define the actual “linkFunction”.
  • The link function get 4 parameters: scope, element, attributes and controller.
  • The controller parameter is a reference to the controller declared for the directive.
  • The element parameter represents the top level element of the directive.
  • The scope parameter is used to attach properties on the scope just like in a controller.


MVVM design pattern has a clear indication that we do not want to directly manipulate the DOM. Instead, AngularJS do it for us using declarations of property bindings and so on.


@eusebiuschipor: Manipulate the DOM with directive link in AngularJS 1.x #angularjs #javascript #frontend

Posted on January 06, 2017

MVVM design pattern has a clear indication that we do not want to directly manipulate the DOM. Instead, AngularJS do it for us using declarations of property bindings and so on.

After we’ve declared the link function in our directive we have to define the actual “linkFunction”. The link function get 4 parameters: scope, element, attributes and controller. The scope parameter is used to attach properties on the scope just like in a controller. The element parameter represents the top level element of the directive. The attributes parameter is an object that contains references to the attributes declared on the element. The controller parameter is a reference to the controller declared for the directive.

function Directive() { var dir = { scope: { … }, link: linkFunction, templateURL: ‘my-template.html’ }; return dir; }

Eusebiu Schipor Let’s talk tech!