私は抽象クラスを使用してさまざまなソースからデータを表示しています。すべてのソースは抽象クラスに注入され、コンポーネント内のデータを表示します。アングル4の抽象クラスの動的な複数プロバイダ
これは、データを取得するには、抽象クラスを使用している私のコンポーネント、次のとおりです。
import {AbstractclassService} from '../../../../abstractclass.service';
import {Source2-Service} from '../../../../Source2.service';
import {Source1-Service} from '../../../../Source1.service';
@Component({
selector: 'app-gauge',
templateUrl: './gauge.component.html',
providers: [
{
provide: AbstractclassService,
useValue: Source1-Service , Source2-Service
multi: true
}
],
styleUrls: ['./gauge.component.css']
})
export class GaugeComponent implements OnInit {
data = [
{
name: 'test',
value: 'test'
}
];
constructor(public abstractclassService: AbstractclassService ) {}
ngOnInit() {
this.abstractclassService.onMessage = (msg: string) => {
this.data = [{name: 'test', value: msg}];
};
}
そして、これはサービスとしての私の抽象クラスです:
今@Injectable()
export abstract class AbstractclassService {
public onMessage(msg: string): void {
console.log("Testing");
}
}
、私はdidnのuseValue異なる注入源に注入する方法を教えてください。
を持っている私はあなたが何をしたいですか理解していません。 Source1-ServiceとSource2-Serviceをコンポーネントに注入したいのですか? – mickaelw
私は抽象クラスを注入したいだけで、抽象クラスはソースとして複数のサービスを使用します。 – Steffn
だから私はどの新しいソースで使用したいソースを選択したいのですか? – Steffn