我刚开始使用angular 2.所以我尝试使用Web服务从数据库中显示类别 .
这是我的forum.service.ts文件
public getCategories(){
return this.http.get('http://localhost/ForumLaraAngular/public/api/forum').map((res: Response) => res.json());
}
forum.component.ts:
categories:any;
constructor(private forumService:ForumService) { }
ngOnInit(): void {
this.forumService.getCategories().subscribe((data)=>{this.categories=data;})
}
forum.component.html:
<categories>
<ul>
<li *ngFor="let categ of categories"> {{categ.titre}}</li>
</ul>
</categories>
请提前帮助,谢谢
1 回答
从选择器中写出以下代码行