Am get data from the backend(api) and displaying it using ngFor like this:
<li *ngFor="let event of events">
{{event.name}}
{{event.city}}
</li>
my results is like this;
wedding
city 1
graduation
city 2
now i want to fetch detail information about an event when a user click on the event and i want to achieve this by passing an event_id which i didn't display to the view to the back-end.
<li *ngFor="let event of events" (click)="moreDetails(event)">
{{event.name}}
{{event.city}}
</li>
And then in my component:
moreDetails(ev){
//
this._http.get(this.url + event_id)
.map((res:Response) => res.json())
.subscribe(
data => this.getEventData = data,
error =>this.logError(error),
() => console.log('get request completed sucesfully')
);
}
thanks in advance
答案 0 :(得分:0)
I assume your events have ids, so your event id will be ev.id
moreDetails(ev){
//
this._http.get(this.url + ev.id)
.map((res:Response) => res.json())
.subscribe(
data => this.getEventData = data,
error =>this.logError(error),
() => console.log('get request completed sucesfully')
);
}
答案 1 :(得分:0)
只需将你的唯一键(id)和url通过追加(或者我们可以说是使用unique_id连接字符串)传递给它,就像这样: -
htmlentities($address)