I am trying to use switchMap
combined with template async
pipe so I think I need to return an Observable
. But this is just not working.
this.route.params.switchMap( (params: Params) =>
this.course = this.courseService.get(params['id'])
);
I thought in the template
<div *ngif="course | async as c">
{{c.name}}
</div>
should subscribe this observable and trigger the request to server but it seems not. What did I misunderstand here? The same approach seems ok with ngFor
on Observable
array.
Fixed this by, ( still confusing what switchMap does here, I steal it from somewhere):
this.route.params.subscribe( params => this.course = this.courseService.get(params['id']));
Anyone can explain, why switchMap not working in this case.
In my other project, this works:
this.route.params
.switchMap((params: Params) =>
this.journalService.getJournal(+params['id']))
.subscribe( (journal) => {
this.journal = journal;
});