I have a implemented a custom Pipe in Angular 2 RC5 which processes data that I get from the server. The problem I'm having is that the Pipe executes before the ngOnInit
which is where I am making the calls to the server.
As a test I passed an-already populated list to the Pipe and everything works as expected. The only issue I'm having is that the Pipe executes when the page is rendered. And so the list in that case is empty.
Is there any way to "delay" the rendering of the page so that when the Pipe executes it has the data retrieved from the server?
This is a sample of my code:
Component
ngOnInit() {
Observable.forkJoin([
this.testService.get(),
this.multilingualService.get(localStorage.getItem('currentPage'))
]).subscribe(servicesResult => {
this.mainList = servicesResult[0];
this.pageMultilinguals = servicesResult[1];
},
error => this.handleError(error));
}
Pipe
@Pipe({name: 'multiLang'})
export class MultilingualPipe implements PipeTransform {
transform(value: string, pageMultilinguals: Multilingual[], context: number): string {
for (let i = 0; i < pageMultilinguals.length; i++) {
if (pageMultilinguals[i].reference === value && pageMultilinguals[i].contexTypeId === context) {
return pageMultilinguals[i].value;
}
}
}
}
Template
<span>{{ 'Test' | multiLang: pageMultilinguals: 9 }}</span>