angular7 - 我想在 for 循环中显示特定记录的标签文本
问题描述
<div ngFor="let data of Requests">
FirstName:<b>{{data.name}}</b>
<button (click)="AcceptRequest()">Accept</button>
<button (click)="CancelRequest()">Decline</button>
<label>{{RequesStatus}}</label>
我只想在我为每个请求显示的代码中显示接受或拒绝该请求的请求的标签。
解决方案
试试这个,这应该工作:
<div *ngFor="let item of requests; index as ix">
ix: {{ix}} FirstName:<b>{{item.name}}</b>
<button (click)="HandleRequest(true, ix)">Accept</button>
<button (click)="HandleRequest(false, ix)">Decline</button>
<label>{{requesStatus[ix]}}</label>
<!-- or -->
<label>{{(isAccepted[ix]) ? 'accepted' : 'declined'}}</label>
</div>
在 TS
// in class level declare this
requesStatus: string[] = [];
// or
isAccepted: boolean[] = [];
// function to set and use in template
HandleRequest(accepted, ix) {
this.requesStatus[ix] = (accepted) ? 'accepted' : 'declined';
// or
this.isAccepted[ix] = accepted;
}
推荐阅读
- php - 为什么 PHP 将我的函数打印为字符串?
- css - 下划线 WP 主题 CSS 将侧边栏移到一边
- python-3.x - 我正在随机修改 HSV 颜色,但颜色不是应有的颜色
- javascript - 如何阻止我的 Javascript 代码弄乱我预定义的 CSS 样式?
- python - 如何在目录中获取png文件并将其重命名为特定名称python
- angular - 在 ts 中更改变量时,Angular 2 视图未更新
- ios - 如何在 Ios swift 中向 BLE 设备写入多个命令
- javascript - GoogleIMA:1009 VAST 响应文档为空
- nlp - 仅从训练数据或整个数据中构建词汇表?
- javascript - 从 Ajax 调用结果中读取对象