I\'m building a directive which supposed to take html file, place it in dom and compile it with angular\'s compile
I\'m getting an error:
$te
The second parameter to link-function is element. If you´re trying to inject $templateRequest and $compile you need to do it in the constructor:
export class uniTable implements ng.IDirective {
constructor(private $templateRequest: ng.ITemplateRequestService, private $compile: ng.ICompileService){
}
public restrict: string = 'EA';
public link: Function = (scope: ng.IScope,
element: ng.IAugmentedJQuery,
attrs: ng.IAttributes) => {
this.$templateRequest("template.html",false).then(function (html) {
var template = angular.element(html);
element.append(template);
$compile(template)(scope);
});
}
}
angular
.module('TModule')
.directive('uniTable', ['$templateRequest','$compile',($templateRequest,$compile) => { return new Uni.Directives.uniTable($templateRequest,$compile) }]);
I'd suggest using function when dealing with factory functions like the directive function. Following this structure:
function uniTable($templateRequest: ng.ITemplateRequestService, $compile: ng.ICompileService): ng.IDirective{
return {
restrict: 'EA',
link: function(){
$templateRequest()//doStuff
}
};
}
uniTable.$inject = ['$templateRequest', '$compile'];
angular.module('TModule')
.directive('uniTable', uniTable );