【发布时间】:2014-11-06 20:34:06
【问题描述】:
在这里查看答案:https://stackoverflow.com/a/19272093/2547709
使用 $inject 语法,我的控制器最终看起来像这样:
class MyCtrl {
public static $inject: string[] = ['$scope'];
constructor($scope){
// stuff
}
}
// register the controller
app.controller("MyCtrl", MyCtrl);
我的问题是 - 如果我想将自己的自定义参数以及任何注入的变量传递给构造函数会发生什么?:
class MyCtrl {
public static $inject: string[] = ['$scope'];
constructor($scope, customArg){
// stuff
}
}
// Now how do I pass customArg in without it complaining?
app.controller("MyCtrl", MyCtrl(customArg)); // Nope
我觉得我错过了一些基本的东西,使用这种语法,你传递给 .controller() 函数的所有东西都必须用 angular 注册,所以我根本不应该尝试传递自定义参数?或者我可以传入任意值/对象吗?如果是这样怎么办?
【问题讨论】:
-
你想通过什么例子?你能用 angular.value 用 angular 注册它吗?
标签: angularjs typescript