Calling the CSS style from typescript append it to html file

送分小仙女□ 提交于 2019-12-11 06:40:55

问题


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


回答1:


Use ngClass to add a class conditionally:

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


来源:https://stackoverflow.com/questions/54439571/calling-the-css-style-from-typescript-append-it-to-html-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!