This is a piece of code that recreates my problem:
HTML:
... <div ng-controller="worker as workerCtrl"> <my-directive label="label" controllerAs="workerCtrl" function="fileUpload(e, this.options)"></my-directive> </div>
controller:
... function fileUpload(file, options){...} ...
directive:
function myDirective($compile) { var directive = { restrict: 'E', link: link }; return directive; function link(scope, element, attrs) { var htmlText = '<lx-file-input ' + 'change="'+attrs.controllerAs+'.'+attrs.uploadFunction+'" ' + 'label="'+attrs.label+'"></lx-file-input>'; element.replaceWith($compile(htmlText)(scope)); } }
It should be: ('lx-file-input' is a third-party directive ...)
<lx-file-input change="workerCtrl.fileUpload(e, this.options)" label="someLabel"</lx-file-input>
The problem is that Angular compilation and linking time is disabled, and the templates are left with an HTML string instead of a compiled function. I know this will work if I install the controller inside the directive, but I want it to use the same function in the same "workerCtrl" area from HTML.
source share