提问人:Ahmed Ejaz 提问时间:11/9/2023 更新时间:11/13/2023 访问量:17
想要使用ngFor范围之外的变量
Want to use a variable outside the scope of ngFor
问:
<mat-select [(ngModel)]="e1Instance" (selectionChange)="e1InstanceChanged(item)"> <mat-option *ngFor="let item of entities" value={{item.name}} >{{item.name}}</mat-option></mat-select>
嗨,社区,
这就是我想使用代码的方式......
我想在 (SELECTIONCHANGE) 的第一行使用 item 变量
如果我将我的 ngFor 移到上面,它会造成混乱,进行多个垫子选择。
任何建议
我想在 (SELECTIONCHANGE) 的第一行使用 item 变量 如果我将我的 ngFor 移到上面,它会造成混乱,进行多个垫子选择。 任何建议
答:
0赞
Ahmed Ejaz
11/13/2023
#1
这是我找到的解决方案:
- 在 Mat-Option 上创建一个新函数 onClick。
- 在 TS 文件中创建该函数。
- 将当前实体的值保存在其他变量中。
- 在 SELECTIONCHANGE 中传递该变量。
评论