AngularJS 依赖注入在模块中失败
AngularJS Dependency Injection Fails in module
我对角度依赖注入机制有问题。我在一个独立的模块中编写了一个指令,它在数据表上做了一些简洁的事情。我正在使用TypeScript,我的指令如下所示:
export class MdListControls implements angular.IDirective {
public templateUrl = "/app/templates/mdListControls.html";
public static instance(): any {
return new MdListControls();
};
public restrict = 'E';
public transclude = true;
public replace = true;
public scope = {
grid: '=',
};
public controller = "mdListControlsController"
public controllerAs = "vm";
public link = function (scope: angular.IScope, element: angular.IAugmentedJQuery, attrs: angular.IAttributes) {
};
}
我的控制器如下所示:
export class MdListControlsController {
static $inject = ['scope']
constructor($scope: angular.IScope){
//Setup the constructor
}
//Here goes the controller Logic
}
我正在新模块上注册指令和控制器,如下所示:
angular.module("base.directives.mdListControls", [])
.controller("mdListControlsController", MdListControlsController)
.directive("mdListControls", function () { return MdListControls.instance() });
但是,一旦我运行该应用程序,一旦加载指令,就会出现以下错误:
Argument 'mdListControlsController;' is not a function, got undefined
起初,这看起来不太像是依赖注入的问题。但是当我在应用程序本身上注册控制器时(它被注入了"base.directives.mdListControls"模块),就像这样
app.controller("mdListControlsController", MdListControlsController);
一切正常,控制器被正确注入指令中。
有谁知道我在这里做错了什么?感谢您的帮助!
在 MdListControls 类中,尝试提供控制器类,而不是控制器名称。
...
public scope = {
grid: '=',
};
public controller = MdListControlsController
public controllerAs = "vm";
...
相关文章:
- 意外的令牌模块生成失败:SyntaxError
- 使用Q节点模块时,Bluemix node.js应用程序部署失败
- webpack配置警告和错误:;模块解析失败”;
- 添加角光栅时模块实例化失败
- 导入模块失败's css文件
- 模块构建失败:引用错误:[BABEL] 未知选项:base.stage
- webpack 解析模块 'blueimp-load-image' 失败
- Webpack 模块构建失败意外令牌(rails react build)
- 命令失败: gm 识别: 无法打开文件 (2) [没有这样的文件或目录].通用模块和 ES6 承诺的问题
- AngularJS 依赖注入在模块中失败
- AngularJS加载模块失败
- 角度模块加载失败
- Gulp.js安装失败,找不到模块'fetch.js'
- Angular--实例化模块失败
- 为什么当子模块构建失败时,NPM会成功
- 实例化模块失败错误:[$injector:unpr]
- 实例化app模块失败.处理步骤为什么
- 未捕获错误:[$injector:modulerr]实例化模块失败,原因是:
- Grunt失败,提示“无法找到模块”.对于本地模块
- Angularjs、Typescript、Uglify实例化myApp模块失败未知提供商:a