angular - 使用单一属性为其他人设置 *ngif = false
问题描述
我必须更新来自 db 的值。当我单击更新按钮时,我正在使用 ngModel 在文本框中设置值。但对于所有其他记录,文本框正在打开。
代码...
HTML
<li *ngFor="let t of Tutorials ; let i = index">
{{t.name}} --- {{t.url}}
<input type="text" [(ngModel)]="tutName" *ngIf="update">
<input type="text" [(ngModel)]="tutUrl" *ngIf="update">
<button (click)="updateTut(t)">Update</button>
</li>
读取.ts
update : boolean = false;
updateTut(tut : Tutorial){
this.update = !this.update;
if(this.update){
this.tutName = tut.name;
this.tutUrl = tut.url;
this.update = !this.update;
}
请帮忙
谢谢
解决方案
在数组对象中有一个属性调用update
并更新那个
<input type="text" [(ngModel)]="tutName" *ngIf="t.update">
updateTut(tut : Tutorial){
tut .update = !tut .update;
if(this.update){
this.tutName = tut.name;
this.tutUrl = tut.url;
tut.update = !tut.update;
}
推荐阅读
- r - 根据 R 中的数据范围计算值
- c# - restsharp PUT 请求错误 --> “StatusCode: InternalServerError, Content-Type: application/json, Content-Length: -1)”
- javascript - 为什么我在使用 Ext JS 6.2.0 时遇到问题?
- alexa-skills-kit - 如何使用 JOVO 框架获取 Alexa 技能意图的实际话语文本
- excel - 有没有办法提高执行时间?
- html - 点击孩子时不要考虑父母
- python - 如何使用 python/selenium 自动执行网站上的按钮点击序列?
- javascript - FullCalendar, 4.2 - 如何在 eventClick 函数上更改事件类
- javascript - 同一对象上的多个事件侦听器不起作用
- image - 热图像和彩色图像之间的对齐