将ngfor scoped变量作为ngclass中的变量进行className
我正在尝试实现的目标是使用NGFOR SCOPED变量作为标签的类动态更改类别。
<ul formArrayName="pokeTypes">
<li [formGroup]="nestedForm" *ngFor="let type of this.createListOfTypes()|async; let i = index">
<!-- add style! -->
<input type="checkBox" [id]='type' [value]="type" [formControlName]="type"
(change)="onCheckStateChange($event)">
<label [for]="type" [ngClass]="{'{{type}}': pokeTypes.controls[0].get('type').value !== null }">{{type|titlecase}}</label>
</li>
</ul>
```**strong text**
what i'm trying to achieve is to change class dynamically using the value of the ngFor scoped variable as the class of the label.Here's my code:
<ul formArrayName="pokeTypes">
<li [formGroup]="nestedForm" *ngFor="let type of this.createListOfTypes()|async; let i = index">
<!-- add style! -->
<input type="checkBox" [id]='type' [value]="type" [formControlName]="type"
(change)="onCheckStateChange($event)">
<label [for]="type" [ngClass]="{'{{type}}': pokeTypes.controls[0].get('type').value !== null }">{{type|titlecase}}</label>
</li>
</ul>
```**strong text**
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要将ng class用于此
&lt; label [for] =“ type” [ngclass] =“ {'{{type}}}':poketypes.controls [0] .get('type')。值!== null}“&gt; {{type | titlecase}}&lt;/label&gt;
您可以像这样切换类:
class =“ {poketypes.controls.controls [0] .get(get(get)( 'type')。值!== null
?
Don't use ng class for this
<label [for]="type" [ngClass]="{'{{type}}': pokeTypes.controls[0].get('type').value !== null }">{{type|titlecase}}</label>
Instead you can toggle your class like so:
class="{{ pokeTypes.controls[0].get('type').value !== null ? type : '' }}"
Or something similar.