【发布时间】:2019-05-18 21:24:57
【问题描述】:
我不明白为什么在我的输入中看到的是[object Object],而不是占位符;
这是我的html:
<div class="input-form">
<input type="text" placeholder="Type name here..." [(ngModel)]="newItem">
<button (click)="addItem()">Add new</button>
</div>
<ul>
<li *ngFor="let item of items">{{ item }}
<button (click)="deleteItem(item)" >Delete</button>
</li>
</ul>
这里是 component.ts:
newItem = {};
items = [];
addItem() {
if (this.newItem !== null) {
this.items.push(this.newItem);
this.newItem = {};
}
}
【问题讨论】:
-
正如你所定义的
newItem = {}得到结果将其定义为newItem = ''; -
如果你想把它作为一个对象保存,试试 json 管道:
{{ item | json }}
标签: javascript angular typescript angular7