【发布时间】:2018-07-02 13:30:01
【问题描述】:
我有一个显示在视图中的对象数组,我想使用 http get 调用的结果更新数组中的一个对象。
对象(项目)已更新,但是当我调试它时,似乎对象中的这种更改不存在于数组(this.myArray)中,因此视图中没有任何更改。
component.ts
myFunction() {
this.myArray.forEach(item => {
this._appSvc.modifyObject(item).subscribe(result => {
item = result;
});
});
}
appSvs.ts
modifyObject(item): Observable<IItem>{
return this._http.get(url).map(response => <IItem> response.json());
}
component.html
<tbody>
<tr *ngFor="let item of myArray | orderBy:{property: sortingAttribute, direction: direction}">
<td>
<input type="checkbox" name="select-{{item.id}}"
id="select-{{item.id}}"
[checked]="item.selected"
(change)="selectItem(item.id)"/>
</td>
<td>
<span>{{item.name}}</span>
</td>
<td>
<span>{{item.code}}</span>
</td>
</tr>
</tbody>
【问题讨论】:
-
如何将数组与视图绑定?你喜欢 ngOnChanges 吗?
-
@Mium 检查编辑版本!我使用(更改)指令,但用于对象(即数组的元素)
标签: angular typescript angular5