我有此頁面顯示類別列表,如果用戶點擊某個類別,它將顯示該類別的詳細信息。將從http請求獲取的數據從一個頁面傳遞到另一個頁面
getCategory(id) {
const url = 'https://[project-name].firebaseio.com/category/' + id + '.json';
console.log(url);
return this.http.get(url)
.map(res => {
const data = res.json();
console.log(data);
return data;
});
}
在類別列表TS:
getCategory(id) {
this.firebaseService.getCategory(id).subscribe(
res => {
console.logs(res);//returns back title, description, etc
}
);
}
在類別列表HTML:
<a [routerLink]="['/category-details' , tile.id]" mat-button color='primary' (click)="getCategory(tile.id)">View</a>
在我的類別的細節我想要的數據
我的服務從類別列表中傳遞給它並顯示數據。下面是ts:
ngOnInit() {
this.sub = this.route.params.subscribe(params => {
this.id = +params['id']; // (+) converts string 'id' to a number
// In a real app: dispatch action to load the details here.
});
}
我是新的HTTP請求,我想了解更多關於此。我究竟做錯了什麼?