如何在角度更改班级名称

时间:2019-10-15 05:31:08

标签: angular

<ul class="nav nav-tabs" id="myTab" role="tablist">
   <li [className]="titleActive ? 'nav-item active' : 'nav-item'">
      <a class="nav-link active wow fadeIn" id="home-tab" data-toggle="tab" href="#home-1" role="tab" aria-controls="home" aria-selected="true">HOT JOBS</a></li>
    <li class="nav-item">
        <a class="nav-link wow fadeIn" id="profile-tab" data-toggle="tab" href="#profile-1" role="tab" aria-controls="profile" aria-selected="false">ALL JOBS</a>
    </li>
</ul>

Ts文件 titleActive:any ='true';

某些情况  this.titleActive ='false';

2 个答案:

答案 0 :(得分:1)

使用ngClass

<li [ngClass]="titleActive ? 'nav-item active' : 'nav-item'">

答案 1 :(得分:0)

尝试使用[ngClass]

 <li [ngClass]="titleActive == 'true' ? 'nav-item active' : 'nav-item'">
    <!-- content -->
 </li>