in angular prelink won't be called if directive use templateUrl instead of template

363 Views Asked by At

in compileTemplateUrl function of angular.js. the 'controller: null' of derivedSyncDirective cause no controller function stored for that element. so getControllers called in nodeLinkFn(its prelink part) will throw exception so prelink won't be called. see http://plnkr.co/edit/yMcurPowZmxCOv0luE5s I don't understand why 'controller: null' here. Does anybody know it?

1

There are 1 best solutions below

0
On

You need to pass the controller into the directive if you want the controller referenced by name. So first you need to specify the controller with the directive in the template like this

<div ess-tag ng-controller="TagController">
    <span>test</span>
</div>

And in the directive, add require statement, which tells the controller where to find the injected controller if you want the controller referenced by name:

require: 'ngController',
controller: 'TagController',