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) {
    }
}
});

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐