Angular实现tab切换

一、实现效果图

在这里插入图片描述

备注: 数字是后台获取得

二 、实现思路

前端把数据做活,通过点击获取下标得方式实现高亮

三、代码实现

html
在这里插入图片描述
ts
在这里插入图片描述
在这里插入图片描述

四、代码案例

html

 <ul class="tabList">  
        <li *ngFor="let item of tabPendingArr index as i" [ngClass]="activeIndex == i ? 'active':''" (click)="tabGetList(i)">  
        {{item.name}}
        <span>({{item.count}})</span>
      </li> 
      </ul>

ts

 tabNumObj: any;
  activeIndex:Number = 0;
  tabPendingArr: Array<Object>;

 getCount() {
    //  this.homeService.getNewCustomerCount(this.userinfo.consultantId).subscribe(resp => {
    this.tabNumObj = { redistrCount: 7, newRecomCount: 8, phoneUndisCount: 5 }
    let redistr = this.tabNumObj.redistrCount//重分配客户数
    let newRecom = this.tabNumObj.newRecomCount//新推荐客户数
    let phoneUndis = this.tabNumObj.phoneUndisCount //留电待处理客户数

    this.tabPendingArr = [{ name: "重分配客户", type: 1, count: redistr }, { name: "新推荐客户", type: 2, count: newRecom }, { name: "留电待处理", type: 3, count: phoneUndis }]

    // this.loading.hide();
    // });


    this.getCommonDistribution()
  }
  tabGetList(i){
    this.activeIndex = i
  }
备注:
  • angular实现循环数组带下标
    let item of tabPendingArr index as i
<li *ngFor="let item of tabPendingArr index as i" [ngClass]="activeIndex == i ? 'active':''" (click)="tabGetList(i)">  
        {{item.name}}
        <span>({{item.count}})</span>
      </li> 
  • 动态class定义
 [ngClass]="{'pengdingCus':title=='待跟进客户'}">

scss

.tabList{
    display: flex;
    background: #fff;
    height: 40px;
    border-bottom:1px #666666 solid;
    // position: fixed;
    // z-index: 999;
    width: 100%;
    margin-bottom: 1px;
    li{
      width: 33%;
      font-size: 14px;
      text-align: center;
      height: 40px;
      line-height: 40px;
    }
    .active{
      color: #1782F0;
      border-bottom: 2px solid #1782F0;
    }
  }
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值