无法在 ngFor 循环中分配值:无法分配给对象的只读 属性
unable to assign a value in ngFor loop: cannot assign to readonly property of object
temp.html代码
<div>
<div>{{status}}</div>
</div>
<table>
<tr *ngFor="let d of list">
<td>{{d.desc}}</td>
</tr>
</table>
d.desc 具有值:已提交、待定、部分
我想如果 d.desc 处于待处理状态,状态应更改为 pending.I 不要在 ts 文件中循环或过滤
ts 文件有变量
public status:string="ok";
public list:any=[{"desc":"submitted"},{"desc":"pending"},{"desc":"partial"}]
我正在尝试但无法分配给对象
的只读属性
无法直接实现!但是您仍然可以使用函数并通过传递状态从 html 调用该函数。
我为此创建了一个 stackblitz!看看吧!
https://stackblitz.com/edit/angular-a7bxve
在html...
<table>
<tr *ngFor="let d of list">
<td>{{showStatus(d.desc)}}</td>
</tr>
</table>
并且在 ts 文件中...
showStatus(status) {
this.status = status;
}
temp.html代码
<div>
<div>{{status}}</div>
</div>
<table>
<tr *ngFor="let d of list">
<td>{{d.desc}}</td>
</tr>
</table>
d.desc 具有值:已提交、待定、部分 我想如果 d.desc 处于待处理状态,状态应更改为 pending.I 不要在 ts 文件中循环或过滤 ts 文件有变量
public status:string="ok";
public list:any=[{"desc":"submitted"},{"desc":"pending"},{"desc":"partial"}]
我正在尝试但无法分配给对象
的只读属性无法直接实现!但是您仍然可以使用函数并通过传递状态从 html 调用该函数。 我为此创建了一个 stackblitz!看看吧! https://stackblitz.com/edit/angular-a7bxve
在html...
<table>
<tr *ngFor="let d of list">
<td>{{showStatus(d.desc)}}</td>
</tr>
</table>
并且在 ts 文件中...
showStatus(status) {
this.status = status;
}