두 구성 요소와 두 구성 요소가 공유하는 공유 서비스가 있습니다. 두 개의 라디오 버튼이고 하나는 거기angular2 subject가 변경 내용을 구독하지 않습니다.
shared.service.ts
// ..... top level codes are skipped
private pickAnalysisForBubble = new Subject<any>();
analysisForBubble$ = this.pickAnalysisForBubble.asObservable();
mapToggleToPointOrBubble(value) {
this.pickAnalysisForBubble.next(value);
}
utility.component.ts
뷰 (utility.component.html)은 미리 선택된 (0120) 이벤트 : (나는 shared.service
수입 및 공급 업체로이 추가되었습니다.)
changeToPoint(event){
# analysisInteraction is the shared service constructor
this.analysisInteraction.mapToggleToPointOrBubble(event.target.value);
}
map.component.ts
나는 shared.service
을 수입 생성자를 추가 한합니다. 그런 다음 ngOnInit
에서 subscribe
로 변경하려고 시도했지만 이 작동하지 않습니다.
# analysisInteraction is the shared service constructor
this.analysisInteraction.analysisForBubble$.subscribe(
data => {
this.DrawType = data;
console.log("Drawtype fixed");
});
나는이 tutorial에 따라 변화를 감지 할 수 subject
을 사용하고 있습니다. 내가 뭘 잘못하고있어?
예, 두 구성 요소 모두에 'sharedService'를 제공자로 추가했습니다. – Emu
내 'main.ts' 파일에 내 하위 구성 요소에도'sharedService'를 추가했습니다. 그래도 작동이 안되는. 어떤 단서? – Emu
그게 문제입니다 ;-)이 경우 각 구성 요소는 자체 인스턴스를 가지며 동일한 구성 요소를 공유하지 않습니다. 이것은 계층 형 인젝터 때문입니다. –