将ngfor scoped变量作为ngclass中的变量进行className

发布于 2025-02-06 00:52:41 字数 638 浏览 6 评论 0原文

我正在尝试实现的目标是使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鲜肉鲜肉永远不皱 2025-02-13 00:52:42

不要将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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文