• <small id='DnY7D'></small><noframes id='DnY7D'>

      • <bdo id='DnY7D'></bdo><ul id='DnY7D'></ul>
      <legend id='DnY7D'><style id='DnY7D'><dir id='DnY7D'><q id='DnY7D'></q></dir></style></legend>

      1. <i id='DnY7D'><tr id='DnY7D'><dt id='DnY7D'><q id='DnY7D'><span id='DnY7D'><b id='DnY7D'><form id='DnY7D'><ins id='DnY7D'></ins><ul id='DnY7D'></ul><sub id='DnY7D'></sub></form><legend id='DnY7D'></legend><bdo id='DnY7D'><pre id='DnY7D'><center id='DnY7D'></center></pre></bdo></b><th id='DnY7D'></th></span></q></dt></tr></i><div id='DnY7D'><tfoot id='DnY7D'></tfoot><dl id='DnY7D'><fieldset id='DnY7D'></fieldset></dl></div>

      2. <tfoot id='DnY7D'></tfoot>

        如何在角度2中动态更改css类名

        时间:2023-09-08
        <i id='5muYW'><tr id='5muYW'><dt id='5muYW'><q id='5muYW'><span id='5muYW'><b id='5muYW'><form id='5muYW'><ins id='5muYW'></ins><ul id='5muYW'></ul><sub id='5muYW'></sub></form><legend id='5muYW'></legend><bdo id='5muYW'><pre id='5muYW'><center id='5muYW'></center></pre></bdo></b><th id='5muYW'></th></span></q></dt></tr></i><div id='5muYW'><tfoot id='5muYW'></tfoot><dl id='5muYW'><fieldset id='5muYW'></fieldset></dl></div>
            <bdo id='5muYW'></bdo><ul id='5muYW'></ul>
            <tfoot id='5muYW'></tfoot>

              <tbody id='5muYW'></tbody>

              <small id='5muYW'></small><noframes id='5muYW'>

              • <legend id='5muYW'><style id='5muYW'><dir id='5muYW'><q id='5muYW'></q></dir></style></legend>

                  本文介绍了如何在角度2中动态更改css类名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有两个CSS类名如下

                  .icon_heart{颜色:#bdbdbd;}.icon_heart_red{颜色:#a6b7d4;;}

                  我的 HTML 有一个心形图标

                  <div class="icon_heart" *ngIf="showheartIcon">

                  这里我有两个 div 标签,心形图标最初是灰色,点击后我会将其更改为蓝色.

                  这是我的 ts 文件代码:

                   showheartIcon=true;showheartIconRed =假;setWishlistTrue(id){this.showheartIconRed = true;this.showheartIcon = false;}setWishlistFalse(id){this.showheartIconRed = false;this.showheartIcon = true;}

                  我有两个不同颜色的图标.

                  问题

                  是否可以更改图标的类别而不是两个心形图标?

                  我在 JavaScript 中看到我们可以更改它w3schools 简单的方法将类应用于 div 标签,但我是 TypeScript 的新手.如何更改班级?

                  解决方案

                  <div [ngClass]="showheartIconRead ? 'icon_heart_red' : 'icon_heart'">

                  I have two CSS class name as follows

                  .icon_heart{
                       color: #bdbdbd;
                  }
                  
                  .icon_heart_red{
                      color:#a6b7d4;;
                  }
                  

                  My HTML has a heart icon

                  <div class="icon_heart" *ngIf="showheartIcon">
                      <ion-icon name="heart" (click)="setWishlistTrue(category.product_id);" class="heart"></ion-icon>
                  </div>
                  <div class="icon_heart_red" *ngIf="showheartIconRed">
                      <ion-icon name="heart" (click)="setWishlistFalse(category.product_id);" class="heart"></ion-icon>
                  </div>
                  

                  Here I have two div tags, the heart icon is of gray color initially and on clicking that I will change it to blue color.

                  Here is my ts file code:

                    showheartIcon=true;
                    showheartIconRed =false;
                  
                    setWishlistTrue(id){
                      this.showheartIconRed = true;
                      this.showheartIcon = false;
                    }
                  
                    setWishlistFalse(id){
                      this.showheartIconRed = false;
                      this.showheartIcon = true;
                    }
                  

                  I have two icons of different color.

                  Question

                  Instead of having two heart icons is it possible to change the class of the icon?

                  I have seen in JavaScript we can change it w3schools simple way to apply class to the div tag, but I am new to TypeScript. How can I change the class?

                  解决方案

                  <div 
                      [class.icon_heart]="!showheartIconRead"
                      [class.icon_heart_red]="showheartIconRead">
                  

                  or

                  <div [ngClass]="showheartIconRead ? 'icon_heart_red' : 'icon_heart'">
                  

                  这篇关于如何在角度2中动态更改css类名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  1. <tfoot id='QQGXq'></tfoot>
                        <tbody id='QQGXq'></tbody>

                      <small id='QQGXq'></small><noframes id='QQGXq'>

                        • <bdo id='QQGXq'></bdo><ul id='QQGXq'></ul>

                        • <legend id='QQGXq'><style id='QQGXq'><dir id='QQGXq'><q id='QQGXq'></q></dir></style></legend>
                          <i id='QQGXq'><tr id='QQGXq'><dt id='QQGXq'><q id='QQGXq'><span id='QQGXq'><b id='QQGXq'><form id='QQGXq'><ins id='QQGXq'></ins><ul id='QQGXq'></ul><sub id='QQGXq'></sub></form><legend id='QQGXq'></legend><bdo id='QQGXq'><pre id='QQGXq'><center id='QQGXq'></center></pre></bdo></b><th id='QQGXq'></th></span></q></dt></tr></i><div id='QQGXq'><tfoot id='QQGXq'></tfoot><dl id='QQGXq'><fieldset id='QQGXq'></fieldset></dl></div>