如标题所述,我收到以下 TSLint 错误:
'$http' cannot be declared in the constructor
我在互联网上找不到与此错误相关的任何信息。
这是我的代码:
module MyModule {
"use strict";
class MyService {
static $inject = ["$http"];
constructor(private $http: ng.IHttpService) {
}
}
}
最佳答案
就在我发布问题时,我意识到我需要检查我的 tslint.json
文件,我发现了这个:
"no-constructor-vars": true,
显然,这记录在 tslint's github page 上:
no-constructor-vars
disallows the public and private modifiers for constructor parameters.
所以解决方案就是禁用no-constructor-vars
:
"no-constructor-vars": false,
关于typescript - TsLint: '$http' 不能在构造函数中声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30048785/