Currently, I am working on developing an AngularJS directive using TypeScript. While testing my code in the browser, I encountered the following error: TypeError: $compile is not a function at compileComponent.js:14
Interestingly, the TypeScript compiler did not flag any errors.
module dashboard {
function CompileComponent($compile): ng.IDirective {
console.log('Compiler s--');
return {
replace: false,
restrict: 'EA',
link: (scope: ng.IScope, element: ng.IAugmentedJQuery, attrs: ng.IAttributes, ngModel: any) => {
scope.$watch(
function (scope) {
return scope.$eval(attrs.compile);
},
function (value) {
element.html(value);
$compile(element.contents())(scope);
}
);
}
}
}
var dragdropModule = angular.module('dashboard');
dragdropModule.directive("compileComponent", [CompileComponent]);
}