poojari raj
poojari raj

Reputation: 23

Calling the CSS style from typescript append it to html file

On button click function CSS style to be called with in the TS file

html code:

    <div class="overlay-loader">
    <div *ngIf="isLoading" class="loader"></div>
    <p *ngIf="results">{{ results | json }}</p>
    <p *ngIf="error">Error: {{ error | json }}</p>
    </div>
    <p>
    <button (click)="getResult()">Get result</button>
    </p>

Link which i have tried:https://stackblitz.com/edit/angular-loader-kspfhg?ctl=1&embed=1&file=app/app.component.html&view=editor After clicking the button overlay-loader css class to be loaded and once data get fetched css overlay-loader to be dissaper

Upvotes: 1

Views: 1006

Answers (1)

frido
frido

Reputation: 14099

Use ngClass to add a class conditionally:

<div [ngClass]="{'overlay-loader': isLoading}">

Upvotes: 1

Related Questions