2
我是新的角度,並試圖找出它是如何工作的。我試圖從API中爲我的表提取數據。角度Http獲取方法表
import { Component } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
class AppComponent {
people: any;
constructor(http: Http) {
http.get('https://jsonplaceholder.typicode.com/todos')
.map(res => res.json())
.subscribe(people => this.people = people);
}
}
interface people {
userId:number;
id:number;
title:string;
completed:boolean;
而這個HTML代碼塊
<tr *NgFor="let people of peoples">
<td>{{people.userId}}</td>
<td>{{people.id}}</td>
<td>{{people.title}}</td>
<td>{{people.completed}}</td>
,我做錯了嗎?任何建議非常有幫助。
'* NgFor =「...」' - >'* ngFor =「...」' –
我強烈建議在開始編程之前閱讀更多內容 –