Conditional button attributes


I’m trying to conditionally apply an attribute based on whether a function returns true or false like so:

`<button [attr.secondary]=“isBoosted() ? ‘’: null” full large (click)=“boost()”>



The function isBoosted() returns true, and the attribute is inserted as I’d expect, but the classes that go with the attribute aren’t added so the button doesn’t change colour.

Is this a bug or am I doing something wrong?

Thanks for any help

It works if I change it to use class rather than attribute like so:

`<button [class.button-light]="!isBoosted()" [class.button-secondary]=“isBoosted()” full large (click)=“boost()”>



I’d be happy to know how to conditionally add the attribute directly rather than the class. Did you figure it out?

I have it working like this:

<button [outline]="selectedBell.away" class="i-am-home-button">I Am Home</button>
<button [outline]="!selectedBell.away" class="i-am-out-button">I Am Out</button>

Now if I add a second attribute to the button, say ‘secondary’, the later is not taken into account if the expression for the outline attribute is true:

<button [outline]="selectedBell.away" secondary class="i-am-home-button">I Am Home</button>
<button [outline]="!selectedBell.away" secondary class="i-am-out-button">I Am Out</button>

So the button can have ‘outline’ and ‘secondary’ but ‘secondary’ alone.

Any clue?

1 Like

@gdeflaux I guess that the problem is related to the following issue:

This code don´t update the changes. It´s something wrong?

<ion-icon [attr.color]="cliente.estado == 'activo' ? 'success' : 'danger'" name='close' item-start></ion-icon>

No attr. Just [color].

Thanks @rapropos for the quick response.