我有一个显示在视图中的对象数组,希望使用http调用的结果更新数组中的对象。
对象(项)被更新,但当我调试它时,似乎在数组(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>发布于 2018-07-02 13:37:30
根据索引和从服务中获得的新项修改基数组。
myFunction() {
this.myArray.forEach((item,index) => {
this._appSvc.modifyObject(item).subscribe(result => {
this.myArray[index] = result;
});
});
}https://stackoverflow.com/questions/51137382
复制相似问题