2017-07-20 71 views
0

我有一個可觀測聽的URL,我switch它荷蘭國際集團的getRows()它返回一個可觀察的數據拉從與URL參數的API回來。我希望能夠獲得getRows()所做的每個發射的訂閱參考。這是爲了在用戶界面上顯示加載指示器。開關可觀察數據流,搶訂閱每個下

當前的代碼:

this.tableSource = this.urlParamService.getParameterGroup(this.parameterPrefix) 
    .distinctUntilChanged() 
    .map(p => this.getRows(p)) 
    .switch() 
    .share(); 

然後明確的時候我已經改變了參數,我一直在呼籲:

this.tableLoad = this.tableSource.take(1).subscribe((r) => this.rows = this.parseRows(r)); 

但我想啓用組件更新時,外部實體操縱網址,所以我應該訂閱而不是共享tableSource,那麼我怎樣才能得到一個訂閱,每次我打電話getRows(),這可能嗎?

回答

0

我設法解決這個問題是這樣的:

this.urlParamService.getParameterGroup(this.parameterPrefix) 
    .distinctUntilChanged() 
    .do(p => { 
     this.tableLoad = this.getRows(p).subscribe((r) => this.rows = this.parseRows(r)); 
    }) 
    .subscribe(); 

所以我不再試圖同時使用觀察序列爲一個(即使一個依賴於其他),並剛剛訂閱了第二的副作用的第一。