您如何在“*ngfor”循环中呼吁单击复选框的值?
我试图将“单击”项目的值调用为 *ngfor循环中的一个。到目前为止,这是我的代码:
html:
<form [formGroup]='skillChoice'>
...
<li *ngFor='let skill of skills'>
<mat-checkbox
[disabled]='enableSkill(skill)'
[formControlName]='skill'
(click)='onClick(skill)'
>
{{ skill }}
</mat-checkbox>
</li>
ts:
ngOnInit(): void{
this.skillChoice.valueChanges.subscribe(val => {
// val = {skill1: true, skill2: false, skill3:false...}
... //other various code
let skillTracker = new Array()
// skillTracker needs to be an array of recently clicked items,
// putting them in order of when they were clicked, not
// alphabetically.
// i.e. skillTracker = [skill1, skill5, skill3]
// if skill1 is clicked first, and skill3 is clicked last
}
}
...
onClick(skill: string) {
return skill
}
在我的研究中,我发现使用this.skillchoice.get(“&lt;在此处插入技能名称”)
会读取Boolean值技能。但这不是我想要的。我希望它可以阅读并打印val
数组的“技能”键。有没有办法调用在valuechanges.subscribe
中单击的“事件”,而无需为循环创建val
中的技能循环?
I'm trying to call the value of the "clicked" item for a that is in an *ngFor loop. So far, this is my code:
HTML:
<form [formGroup]='skillChoice'>
...
<li *ngFor='let skill of skills'>
<mat-checkbox
[disabled]='enableSkill(skill)'
[formControlName]='skill'
(click)='onClick(skill)'
>
{{ skill }}
</mat-checkbox>
</li>
TS:
ngOnInit(): void{
this.skillChoice.valueChanges.subscribe(val => {
// val = {skill1: true, skill2: false, skill3:false...}
... //other various code
let skillTracker = new Array()
// skillTracker needs to be an array of recently clicked items,
// putting them in order of when they were clicked, not
// alphabetically.
// i.e. skillTracker = [skill1, skill5, skill3]
// if skill1 is clicked first, and skill3 is clicked last
}
}
...
onClick(skill: string) {
return skill
}
In my research, I found that using this.skillChoice.get("<insert skill name here>")
would read the boolean value of the skill. But that's not what I want. I want it to read and print the "skill" key of the val
array. Is there a way to call the "event" of clicking within the valueChanges.subscribe
without creating a for
loop on the skills in val
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论