angular - 只有一个按钮可以处于“NO”状态
问题描述
我开发了一组输入,每个输入都有一组按钮,这些按钮会根据点击而变化。
每个按钮都以“是”状态开始,但如果单击它,它会变为“否”状态。
有没有办法只将一个按钮置于“否”状态?也就是说,如果一个按钮已经处于“否”状态,当您单击另一个按钮时,该按钮将变为“是”,最后一次单击变为“否”。
谢谢!
代码
<div class="Submitcomments" *ngFor="let c of data; let i = index;">
<div>
<div class="row rowComments" style="margin-top: 11px;">
</div>
<div class="form-group">
<textarea #myinput type="text" class="form-control AreaText" rows="2"></textarea>
</div>
<div class="row" style="margin-top: -20px; margin-left: 5px;">
<button *ngIf="c.currentState=='pause'" class="btn reply" (click)="c.currentState='start'; focus()">Yes</button>
<button *ngIf="c.currentState=='start'" class="btn reply1" (click)="c.currentState='pause'; focus()">No</button>
</div>
</div>
</div>
data = [
{
ID:1,
Name : "Name",
currentState: "pause"
},
{
ID:2,
Name : "Name2",
currentState: "pause"
},
{
ID:3,
Name : "Name3",
currentState: "pause"
},
{
ID:4,
Name : "Name4",
currentState: "pause"
},
];
解决方案
您只能为更改状态添加切换方法。
app.component.html
<div class="row" style="margin-top: -20px; margin-left: 5px;">
<button class="btn reply" (click)="focus();toggleButton(i)">{{c.currentState == 'start' ? 'No' : 'Yes'}}</button>
</div>
app.component.ts
toggleButton(index) {
this.data[index].currentState = this.data[index].currentState == "start" ? "pause" : "start";
}
推荐阅读
- node.js - 获取 razorpay 付款详细信息
- php - Symfony:不断收到有关缺少翻译的通知
- django - 找不到 Django CKEditor 404 图像
- google-cloud-dataflow - GoogleCloudOptions 没有所有选项
.options 有 - python - 如何使用 tkinter 设置 MessageBox 的位置
- python - 在 django 模板中设置和访问变量值的问题
- python - 函数不能解释nan值
- angular - 是否可以在 Angular 7 中使用 npm local-devices
- python - 从 python tkinter 画布创建矢量图像
- html - 窗口大小变化时如何垂直或水平对齐图标