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

6
  • what are you trying to fetch? Could it be a very long (too long) array? stackoverflow.com/questions/22123769/… Commented Aug 16, 2017 at 7:54
  • To support the comment above, try to return a small array from the service and test if it is it Commented Aug 16, 2017 at 7:55
  • I just begin with 4 elements Commented Aug 16, 2017 at 8:07
  • Remove <categories> </categories>. Why did you use it for? Commented Aug 16, 2017 at 8:09
  • it's the selector Commented Aug 16, 2017 at 8:16

1 Answer 1

-1

Write following lines of code out of selector

<ul>
<li *ngFor="let categ of categories"> {{categ.titre}}</li>
</ul>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.