2017-07-17 47 views
0

我有以下管:管與ChangeDetectorRef不被刷新上訂閱事件

{{ "value" | translationPipe | async }} 


translationPipe { 

constructor(otherService: OtherService, myService: MyService, _ref : ChangeDetectorRef) { 
    this.myService.myEventEmitter.subscribe(value -> { 
     _ref.markForCheck(); 
    }); 
} 

transform(value, args?) { 
    // this returns an api call observable 
    return this.otherService.doApiCall(); 
} 

} 

然而,當事件發射器輸出管的值不reobtained一個事件。

+0

爲什麼你認爲它會被重新評估? – yurzui

+0

@yurzui調用_ref.markForCheck會觸發reavaluation它不會? – mangusbrother

+0

@mangusbrother它標誌着變化檢測的* view *。管道沒有看法。 – cgTag

回答

1

角度變化檢測檢查傳遞給管道的值和參數以進行更改。如果他們不改變,調用markForCheck()只是浪費CPU。

解決方法可能是使用pure: false並返回緩存的結果,直到myEventEmitter發出一個事件。