2016-07-24 5 views
0

2 개의 AJAX 요청의 결과가 어느 정도 계산 될 때까지 기다려야합니다.Observable.forkJoin 구독이 절대 호출되지 않습니다

나는이 작업을 수행하는 것으로 보이는 Observable.forkJoin 메서드를 발견했습니다. 그래서 내 구성 요소에 내가 추가 한 :

import { Observable } from 'rxjs/Rx'; 

// ... 

ngOnInit() { 
    Observable.forkJoin(
     this.instrumentService.current, 
     this.tuningService.tunings 
    ).subscribe(
     data => { 
      console.log(data); 
     } 
    ); 
} 

아약스 요청이 전송됩니다하지만 난 subscribe 콜백을 전달하지 않았다. 나는 각 요청을 실행하려고 separatly 잘 작동하는 경우

:

데이터 서비스 ( instrumentServicetuningService)에서
this.instrumentService.current.subscribe(instrument => { 
    console.log(instrument); 
    this.instrument = instrument; 
}); 

this.tuningService.tunings.subscribe(tunings => { 
    console.log(tunings); 
    this.tunings = tunings; 
}); 

에서, Observable이 버그의 아마 소스 (다음과 같이 선언,하지) 알고

private _tunings: BehaviorSubject<Tuning[]> = new BehaviorSubject([]); 

/** 
* Class constructor. 
* 
* @param {ApiService} apiService 
*/ 
constructor (private apiService: ApiService) { 
    this.getAll().subscribe(tunings => this._tunings.next(tunings)); 
} 

public get tunings() { 
    return this._tunings.asObservable(); 
} 

public getAll(): Observable<Tuning[]> { 
    return this.apiService.call(this.url); 
} 

apiService가 내장 된 각도 http 서비스를 호출 할 책임이있다. Observable 반환 null 중 하나가 다음 forkJoin 구독이 호출되지 않은 경우

답변

2

는 지금까지 내가 forkJoin 기억으로 현재 버그가 있습니다. 대신 .zip을 사용해 볼 수 있습니까?

+0

예. 그렇습니다. 내 BehaviorSubject 중 하나는 초기 상태로 'null'을 사용합니다. 'zip' 메소드로 잘 작동합니다. 감사. – Elorfin

관련 문제