I'm new to Angular, but familiar with Javascript.
I'm setting up a CRUD for a demo and can't get this list to loop over data returned from our API.
The data is loading fine, I can see it in the console. But the *ngFor
below does not render any <li>
s.
pages.component.html:
<div class="row">
<div class="col-sm-4">
<p>Pages</p>
<ul>
<li *ngFor="let page of pages">
{{page.Name}}
</li>
<li>this shows up.</li>
</ul>
</div>
</div>
pages.component.ts:
import { Component, OnInit } from '@angular/core';
import { PageService } from '../page.service';
import { Page } from '../page';
@Component({
selector: 'app-pages',
templateUrl: './pages.component.html',
styleUrls: ['./pages.component.css']
})
export class PagesComponent implements OnInit {
pages: Page[];
getPages(): void {
this.pageService.all().subscribe(function(pages) {
console.log(pages);
this.pages = pages;
}
}
constructor(private pageService: PageService) { }
ngOnInit() {
this.getPages();
}
}
Like I said, the data shows up in the console, so I think it must be in the view.