Angular Can';无法解析服务提供商的所有参数?
我在每个组件中都使用一个服务作为提供者:Angular Can';无法解析服务提供商的所有参数?,angular,angular6,angular8,Angular,Angular6,Angular8,我在每个组件中都使用一个服务作为提供者: export class LayersSemanticService { constructor( private nMapLibrary: MapLibraryService, private linkService: LinkService ) { } } 例如: @Component({ selector: "app-intersection-layer-component", templateUrl: "
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]
})
问题是我得到了这个eror:
compiler.js:2175 Uncaught Error: Can't resolve all parameters for LayersSemanticService: (?, ?).
它可以通过使用服务作为根服务来解决,但我需要单独的服务实例。即使您在组件
提供者中声明层语义服务
,您仍然需要将服务标记为@Injectable()
@Injectable()
导出类LayersSemanticService{
建造师(
私有nMapLibrary:MapLibraryService,
专用链接服务:链接服务
) {
}
}
从中,@Injectable
是一个:
将类标记为可提供并作为依赖项注入的修饰符
演示:
在服务之上使用Injectable。如何将MapLibraryService
和LinkService
配置为提供者?它们是在根目录中提供的吗?MapLibraryService
正如在“根目录”中提供的那样,LinkService
也是在“根目录”中提供的问题是一个实例服务引用另一个实例服务,如何解决它?当我从服务调用方法时:让数据=getObjectSemantic(语义:LayerItemGeneric):ObjectInformation自定义{}
并在另一个组件中调用相同的方法,它会重写结果let数据;我不理解您的问题。您是否希望每个组件都有一个实例?是的,但现在它作为一个全局实例工作,因为调用方法对我使用此服务的所有组件都有效后,您能否创建一个stackblitz来演示您的问题是,10几分钟我就可以了
@Injectable()
export class XyzService{
constructor(
) {
}
}