无法解析服务提供商的所有参数?
Can't resolve all parameters for service provider?
在每个组件中都有一个我用作提供者的服务:
export class LayersSemanticService {
constructor(
private nMapLibrary: MapLibraryService,
private linkService: LinkService
) {
}
}
作为实例使用:
@Component({
selector: "app-intersection-layer-component",
templateUrl: "./intersection-layer-component.component.html",
styleUrls: ["./intersection-layer-component.component.scss"],
providers: [LayersSemanticService]
})
问题是我得到这个错误:
compiler.js:2175 Uncaught Error: Can't resolve all parameters for LayersSemanticService: (?, ?).
可以通过将服务用作根服务来解决,但我需要单独的服务实例。
即使您在组件 providers
中声明LayersSemanticService
,您仍然需要将服务标记为 @Injectable()
。
@Injectable()
export class LayersSemanticService {
constructor(
private nMapLibrary: MapLibraryService,
private linkService: LinkService
) {
}
}
来自the docs,@Injectable
是一个:
Decorator that marks a class as available to be provided and injected as a dependency.
@Injectable()
export class XyzService{
constructor(
) {
}
}
在服务之上使用 Injectable。
在每个组件中都有一个我用作提供者的服务:
export class LayersSemanticService {
constructor(
private nMapLibrary: MapLibraryService,
private linkService: LinkService
) {
}
}
作为实例使用:
@Component({
selector: "app-intersection-layer-component",
templateUrl: "./intersection-layer-component.component.html",
styleUrls: ["./intersection-layer-component.component.scss"],
providers: [LayersSemanticService]
})
问题是我得到这个错误:
compiler.js:2175 Uncaught Error: Can't resolve all parameters for LayersSemanticService: (?, ?).
可以通过将服务用作根服务来解决,但我需要单独的服务实例。
即使您在组件 providers
中声明LayersSemanticService
,您仍然需要将服务标记为 @Injectable()
。
@Injectable()
export class LayersSemanticService {
constructor(
private nMapLibrary: MapLibraryService,
private linkService: LinkService
) {
}
}
来自the docs,@Injectable
是一个:
Decorator that marks a class as available to be provided and injected as a dependency.
@Injectable()
export class XyzService{
constructor(
) {
}
}
在服务之上使用 Injectable。