Ben Aston Ben Aston - 5 months ago 8
AngularJS Question

Is the return value of the link function of a directive used?

Is the return value of the

link
function of a directive used?

I am using AngularJS 1.4.

This question stems from seeing an object being new'd up and then returned from a
link
function.

For example, from a directive definition:

// ...
link: function(scope, $element, attrs, ngModelController) {
return new Link(scope, $element, $window, ngModelController);
},
// ...

Answer

Seems that it is not used.

To check it, i set up this simple plunker example, wrote a dummy directive that only has debugger; to set up a breakpoint e.g.

app.directive('myDirective', function(){
  return {
    link: function(scope){
      debugger;
    }
  }
});

While running it, i opened the debugging tools using the F12 key and when looked up in the Call Stack, saw that no one consumes the returned value of the link function call

enter image description here