Angular 6注入ParentService而不是ChildService

时间:2018-07-22 11:50:27

标签: angular

使用以下代码时,

easyrtc接收AppComponent实例而不是ParentService

ChildService

如何获取import { Component, Injectable } from '@angular/core'; @Injectable({ providedIn: 'root' }) class ParentService { name = 'parent'; } @Injectable({ providedIn: 'root' }) class ChildService extends ParentService { name = 'child'; } @Component({ selector: 'my-app', templateUrl: './app.component.html', styleUrls: [ './app.component.css' ] }) export class AppComponent { logs = []; constructor(childService: ChildService) { this.logs.push('childService instanceof ChildService: ' + (childService instanceof ChildService)); this.logs.push('childService instanceof ParentService: ' + (childService instanceof ParentService)); this.logs.push('childService name: ' + childService.name); } } 实例?谢谢。

https://stackblitz.com/edit/angular-ypq7ag

0 个答案:

没有答案