javascript – AngularJS Typescript – 指令内的控制器
作者:互联网
我试图将我的整个类包含控制器添加到我的指令中,因为一些显而易见的原因,范围和语法不正确.
我使用typescript作为语言和grunt-ts进行自动生成和编译.
/// <reference path="../reference.ts" />
directives.directive('myDirective', function ():ng.IDirective {
return {
restrict: 'EAC',
template: directiveHTML.html, \\ thanks to grunt-ts this work fine
controller: MyControllerClass, \\ here I get the error and here I would like to
put my own controller class instead of a function
link: function (scope, elements, attrs) {
}
}
});
在这里我的控制器的类
module Controllers {
export class CursorController {
constructor($scope, socket){
}
}
}
然后将所有控制器添加到angularJS的控制器模块中(引用由grunt-td自动生成).
/// <reference path="../reference.ts" />
angular.module('controllers',[]).controller(Controllers);
关于如何解决这个问题的任何线索或建议都会很棒.
解决方法:
你应该能够做到:
directives.directive('myDirective', function ():ng.IDirective {
return {
restrict: 'EAC',
template: directiveHTML.html, \\ thanks to grunt-ts this work fine
controller: Controllers.CursorController, \\ Lookup controller by name
link: function (scope, elements, attrs) {
}
}
});
标签:javascript,typescript,angularjs,gruntjs,controller 来源: https://codeday.me/bug/20190831/1773591.html