我有这个抽象类作为组件基础:
protected constructor(
protected model: Type<T>,
protected activatedRoute: ActivatedRoute,
protected router: Router,
protected service: CrudServiceBase<T>,
private ng7MatBreadcrumbService :Ng7MatBreadcrumbService
) {}
ng7Mat面包屑服务不依赖于组件,但我必须在每个子组件中传递此服务!有没有办法使用 ng7MatBreadcrumbService 而不在每个子组件中传递它?
您需要将它注入到使用它的每个组件中。装饰器 @Injectable(( 表示您需要注入它才能使用。服务本身意味着它应该被注射,你只需选择注射的类型。
更多关于它的信息在这里: https://angular.io/guide/dependency-injection