【发布时间】:2020-07-10 11:40:35
【问题描述】:
我有一个文字类型作为我的服务的构造函数参数:
export type MyType = 'val1' | 'val2';
@Injectable()
export class MyService {
myType: MyType;
constructor(private appService: AppService, private myType: MyType = 'val2') {
this.myType = myType;
}
}
我在构建时遇到错误
Nest can't resolve dependencies of the MyService (AppService, ?). Please make sure that the argument String at index [1] is available in the AppModule context.
Potential solutions:
- If String is a provider, is it part of the current AppModule?
- If String is exported from a separate @Module, is that module imported within AppModule?
@Module({
imports: [ /* the Module containing String */ ]
})
你会如何解决这个问题?
那是我的 AppModule:
@Module({
imports: [HttpModule],
controllers: [AppController],
providers: [AppService, MyService, HttpClient],
})
export class AppModule {}
【问题讨论】:
-
你是否在你的模块文件中为 Nest 注入任何东西给
MyType? -
@JayMcDoniel 刚刚用我的
AppModule更新了这个问题
标签: dependency-injection service nestjs