admin管理员组文章数量:1279050
I have found some behaviour that I can't understand. If I've got a bunch of styles applied like this:
.monkey-ion-item{
// Country Variant XXXX Not working after upgrade!
&.monkey-variant-search-list-country {
.monkey-icon {
color: var(--ion-color-success, green);
}
}
And then in the html:
<ion-item
[ngClass]="classes"
class="monkey-ion-item"
...
Why does the following work fine:
get classes() {
return `monkey-variant-${this.variant()} ` +
`monkey-input-type-${this.type()} ` +
'monkey-input';
}
Doing this successfully adds all of the listed classes to the ion-item element that they are added to in the template. And they show up perfectly in the properties -> classlist when I inspect the DOM.
but the signal approach to the same fails:
classes: Signal<string[]> = computed(() => [
`monkey-variant-${this.variant()}`,
`monkey-input-type-${this.type()}`,
'monkey-input',
]);
In the case where it fails, if I inspect the DOM, I can see some reference to the classes, but it's clearly not right!
ng-reflect-ng-class=\"[Computed: monkey-variant-sear
I'm migrating code over to use signals and was under the impression that this was the "right" way to do things. But I'm clearly missing something here?!
I have found some behaviour that I can't understand. If I've got a bunch of styles applied like this:
.monkey-ion-item{
// Country Variant XXXX Not working after upgrade!
&.monkey-variant-search-list-country {
.monkey-icon {
color: var(--ion-color-success, green);
}
}
And then in the html:
<ion-item
[ngClass]="classes"
class="monkey-ion-item"
...
Why does the following work fine:
get classes() {
return `monkey-variant-${this.variant()} ` +
`monkey-input-type-${this.type()} ` +
'monkey-input';
}
Doing this successfully adds all of the listed classes to the ion-item element that they are added to in the template. And they show up perfectly in the properties -> classlist when I inspect the DOM.
but the signal approach to the same fails:
classes: Signal<string[]> = computed(() => [
`monkey-variant-${this.variant()}`,
`monkey-input-type-${this.type()}`,
'monkey-input',
]);
In the case where it fails, if I inspect the DOM, I can see some reference to the classes, but it's clearly not right!
ng-reflect-ng-class=\"[Computed: monkey-variant-sear
I'm migrating code over to use signals and was under the impression that this was the "right" way to do things. But I'm clearly missing something here?!
Share Improve this question edited Feb 25 at 6:12 Naren Murali 58.1k5 gold badges44 silver badges76 bronze badges asked Feb 25 at 2:18 monkeymonkey 1,6612 gold badges21 silver badges44 bronze badges1 Answer
Reset to default 2Using the computed is best. Since the output is memoized, if the inputs do not change, the output is not recomputed.
classes: Signal<string[]> = computed(() => [
`monkey-variant-${this.variant()}`,
`monkey-input-type-${this.type()}`,
'monkey-input',
]);
You just need to execute the computed. Since computed is a function we have to execute it to access the value inside.
<ion-item
[ngClass]="classes()"
class="monkey-ion-item"
...
本文标签: cssUsing Angular Signals with classesStack Overflow
版权声明:本文标题:css - Using Angular Signals with classes - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741232017a2362283.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论