更新时间:2022-12-08 16:29:22
@TNII,@Hoang Duc,尝试说您通常是服务公开Observables.订阅Observable时,它位于组件的ngOnInit中.
@TNII, @Hoang Duc, try say you is that generally a service expose Observables. It's in a ngOnInit in your component when you subscribe to the Observable.
//Simple return a get
getAllProductsFromACategory(categoryName: string): any {
return this.http.get('http://localhost:8080/VespaWebshopAPI
/api/Article/Category?categoryName=' + categoryName)
}
在组件中,通常当我们订阅时在ngOnInit中
In the component, generally in an ngOnInit when we subscribe to
ngOnInit()
{
productService.getAllProductsFromACategory('Bremsen').
subscribe(data => {
if (data[0])
this.article=data[0];
})
}
用html编写的{{article?.id}}是一种简短的说法:如果定义了this.article,请向我显示this.article.id.
the {{article?.id}} wrote in the html is a abreviate way to say: if this.article is defined, show me this.article.id.
检查是否在导航器中编写 http://localhost:8080/VespaWebshopAPI /api/Article/Category?categoryName ='Bremsen',为您提供一系列文章.检查数组的元素是否具有id,name等属性(或返回具有其他属性的元素)
check if when in a navigator write http://localhost:8080/VespaWebshopAPI /api/Article/Category?categoryName='Bremsen', give you an array of Articles. Check if the elements of the arrays has properties id,name,etc (or return element with another properties)