【发布时间】:2018-03-31 09:15:28
【问题描述】:
继续示例here,在获得成功的 API 结果后,我无法让 html 组件显示在 TypeScript 组件中定义的整个数据数组。只列出了一个字段。
这里是 todo.component.ts 文件
import { Component, Inject } from '@angular/core';
import { Http } from '@angular/http';
@Component({
selector: 'todo',
templateUrl: './todo.component.html'
})
export class TodoComponent {
public todolist: todo[];
constructor(http: Http, @Inject('BASE_URL') baseUrl: string) {
http.get(baseUrl +'api/todo').subscribe(result => {
this.todolist = result.json() as todo[];
}, error => console.error(error));
}
}
//
interface todo {
Id: number;
TaskName: string;
IsComplete: boolean;
queueing: number;
}
这里是 todo.component.html
<h1>To do List</h1>
<p>This component demonstrates fetching tasks from the server.</p>
<p *ngIf="!todolist"><em>Loading...</em></p>
<table class='table' *ngIf="todolist">
<thead>
<tr>
<th>ID</th>
<th>Task Name</th>
<th>Is complete</th>
<th>queueing</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let item of todolist">
<td>{{ item.Id }}</td>
<td>{{ item.TaskName }}</td>
<td>{{ item.IsComplete }}</td>
<td>{{ item.queueing }}</td>
</tr>
</tbody>
</table>
呈现的 HTML
我做错了什么?
【问题讨论】:
-
使用后端和前端检查模型的属性名称
-
这是蚂蚁的截图吗?对不起,我不得不说。
-
@ZombieChowder 抱歉,我增加了截图大小,现在可以了吗?
-
@Sami-L 是的,只是我在之前的评论中引用了“Zoolander”。
标签: javascript html angular typescript asp.net-web-api