调用构造函数时获取 "error TS2554: Expected 1 arguments, but got 0."
Getting "error TS2554: Expected 1 arguments, but got 0." when calling a constructor
出现错误
error TS2554: Expected 1 arguments, but got 0.
当调用 class 实例时。我该如何解决这个问题?
class ErrorHandler {
constructor(private errorService: BackendErrorsService) {}
getError() {
console.log('error called');
}
}
const instance = new ErrorHandler().getError();
Angular 自动解析组件和服务的依赖关系。但是,当您致电 class
像那样:
const instance = new ErrorHandler().getError();
然后你需要提供一个依赖项BackendErrorsService
。类似的东西:
let backendErrorsService = new BackendErrorsService();
const instance = new ErrorHandler(backendErrorsService ).getError();
出现错误
error TS2554: Expected 1 arguments, but got 0.
当调用 class 实例时。我该如何解决这个问题?
class ErrorHandler {
constructor(private errorService: BackendErrorsService) {}
getError() {
console.log('error called');
}
}
const instance = new ErrorHandler().getError();
Angular 自动解析组件和服务的依赖关系。但是,当您致电 class 像那样:
const instance = new ErrorHandler().getError();
然后你需要提供一个依赖项BackendErrorsService
。类似的东西:
let backendErrorsService = new BackendErrorsService();
const instance = new ErrorHandler(backendErrorsService ).getError();