Answer the question
In order to leave comments, you need to log in
How to filter data by id for a specific element?
There is a page that displays a certain "object". And I want to display a few more of its "object" on the page of this "object", which are linked by child identifiers.
Here is a small JSON example:
[{"object_id":1128,"ch_objects_id":null, "name":TestTitul},
{"object_id":2341,"ch_objects_id":1128, "name":Test2}]
get_filter_show_Objects(): Observable<Object[]> {
return this.authService.get('objects')
.map((response: Response) => <Object[]>response.json()
.filter((object) => object.object_id == object.ch_objects_id))
}
getObject(id: number) {
return this.authService.get('objects' + "/" + id + '.json').catch(this.handleError);
}
objects: Array<Object>;
id: number;
routeId: any;
returnUrl: string;
public errorMsg;
@Input() object: Object;
ngOnInit() {
this.loadObjects();
this.returnUrl = this.route.snapshot.queryParams['returnUrl'] || '/object';
this.routeId = this.route.params.subscribe(
params => {
this.id = +params['id'];
}
)
let objectRequest = this.route.params
.flatMap((params: Params) =>
this.servObject.getObject(+params['id' ]));
objectRequest.subscribe(response => this.object = response.json());
}
private loadObjects() {
this.servObject.get_filter_show_Objects().subscribe(
(data: Object[]) => {
console.log(data);
this.objects = data;
}
);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question