다른 소스의 일부 데이터를 표시하기 위해 추상 클래스를 사용하고 있습니다. 모든 소스는 추상 클래스에 삽입되어 구성 요소에 데이터를 표시합니다.동적 인, 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를 그것을 얻는 방법을 에 사용 가치 다른 소스에 주입?
내가 당신이 원하는 무엇을 이해하지 못하는을 가지고. Source1-Service 및 Source2-Service를 구성 요소에 주입하고 싶습니까? – mickaelw
그냥 추상 클래스를 삽입하고 추상 클래스는 소스 다중 서비스로 사용하려고합니다. – Steffn
그래서 모든 새로운 사례에서 어떤 소스를 사용할지 선택하고 싶습니다 ... – Steffn