Hi Vinu,
don't subscribe in the components class, but prefer the async pipe, as it
is much clearer what is going on.
try something like:
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Http } from '@angular/http';
import 'rxjs/add/operator/mergeMap';
import 'rxjs/add/operator/publishReplay';
@Component({
selector: 'selector-name',
template: `
<tr *ngFor = "let d of viewData$|async">
<td>{{d.name}}</td><td>{{d.type.test1}}</td><td>{{d.type.test2}}</td>
</tr>
`
})
export class NameComponent implements OnInit {
baseData$ = this.http
.get('http://192.168.0.101:8000/json1')
.map(response => response.json())
.publishReplay(1); // This operator "buffers" the result in memory
currentId$ = this.route.params.map(params => params['id']);
viewData$ = this.currentId$.mergeMap(id =>
this.baseData$.map(data => data.filter(row => row.name === id))
);
constructor(private http: Http, private route: ActivatedRoute) {}
ngOnInit() {}
}
Regards
Sander
--
You received this message because you are subscribed to the Google Groups
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.