0

I just begin working with angular 2. so I try to display categories from data base using web service.

this is my forum.service.ts file

   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>

Any help please,thanks in advance

Sara
  • 57
  • 1
  • 2
  • 11

1 Answers1

-1

Write following lines of code out of selector

<ul>
<li *ngFor="let categ of categories"> {{categ.titre}}</li>
</ul>
Rohan Fating
  • 2,135
  • 15
  • 24