How to switch angular2 class using * ngIf

Hello, I need to switch the class using the angular2 operator *ngIf

<i *ngIf="visible" [(ngClass)]="{{arrow}}"></i> <this line of code is not working properly


here is my code ts

private visible = true;
private i = 0;
private arrow = 'ic-v';
private showList(){
    if(this.i == 0){
        this.i = 1;
        this.visible = false;
        this.arrow = 'ic-v-up';
    }
    else
    {
        this.i = 0;
        this.visible = true;
        this.arrow = 'ic-v';
    }
}
+4
source share
1 answer

ngClass is a directive, use it as [ngClass] as an attribute binding directive.

[ngClass]="arrow"

OR even better

[ngClass]="{ 'ic-v': visible, 'ic-v-up': !visible }"

Demo plunker

+6
source

Source: https://habr.com/ru/post/1667916/


All Articles