• Skip to main content
  • Skip to primary sidebar

Web Development Archive

  • Archive
You are here: Home / Angular / Add active class on clicked item

Add active class on clicked item

HTML

<ng-container *ngFor="let tabData of data.list; let i = index">
    <a class="category-tabs-tab" 
        [ngClass]="{ active: activeTab == i }" 
        (click)="activeTab = i" 
        [routerLink]="tabData.routerLink">
    {{ tabData.name }}
    </a>
</ng-container>

TS

import { Component, Input, OnInit } from '@angular/core';

@Component({
  selector: 'kesma-nso-category-tabs',
  templateUrl: './nso-category-tabs.component.html',
  styleUrls: ['./nso-category-tabs.component.scss']
})
export class CategoryTabsComponent implements OnInit {

  activeTab = false;

  constructor() { }

  ngOnInit(): void { }

}

Mock

export const MockCategoryTabs = {
    activeTab: 0,
    name: 'Bajnokok Ligája',
    logoImage: 'https://picsum.photos/64/64',
    list: [
        { name: 'Főoldal', routerLink: ['/'] },
        { name: 'Mérkőzések / Események', routerLink: ['/'] },
        { name: 'Menetrend', routerLink: ['/'] },
        { name: 'Tabella', routerLink: ['/'] },
        { name: 'Átigazolások', routerLink: ['/'] },
    ],
  }

Filed Under: Angular

About Gabor Flamich

I'm a web developer and designer based in Budapest, Hungary. In recent years, I've documented hundreds of solutions I came across during development. This site is an archive for useful code snippets on WordPress, Genesis Framework and WooCommerce. If You have any questions related to WordPress development, get in touch!

Primary Sidebar

  • angular.io
© 2026 WP Flames - All Right Reserved