使用Angular 1.4和ES6 / 7以及Babel,我可以在类块之后使用此代码将参数成功注入到名为Controller的类中:
class Controller {
constructor($scope, $state, $window) {...}
...
}
Controller.$inject = ["$scope", "$state", "$window"]
但是,在构造函数的正上方看到注入参数会更清晰。我见过其他人使用静态$ inject,但是我收到了一个错误。这是我正在尝试的:
class Controller {
static $inject = ["$scope", "$state", "$window"]
constructor($scope, $state, $window) {...}
...
}
为什么会导致此错误?它似乎适用于其他人。
Unexpected token (2:11)
1 | class Controller {
2 | static $inject = ["$scope", "$state", "$window"]
|
^