How to set active tab style with AngularJS ? Last Updated : 08 Sep, 2022 Comments Improve Suggest changes Like Article Like Report In this article, we will see how to set an active tab style using AngularJS, & will also understand its implementation through the example. This task can be accomplished by implementing the isActive and the ng-controller method. We will perform this task with 2 different methods. Method 1: The ng-controller Directive in AngularJS is used to add a controller to the application. It can be used to add methods, functions, and variables that can be called on some event like click, etc to perform certain actions. Syntax: <element ng-controller="expression"> Contents... </element>The below example implements the above approach. Example 1: This example describes setting the active tab style using AngularJS. HTML <!DOCTYPE html> <html> <head> <title> How to set active tab style with AngularJS? </title> </head> <body> <div class="collapse navbar-collapse" ng-controller="HeaderController"> <ul class="nav navbar-nav"> <li ng-class="{ active: isActive('/')}"> <a href="/">Geeks For Geeks</a> </li> <li ng-class="{ active: isActive('/html')}"> <a href="/html">HTML</a> </li> <li ng-class="{ active: isActive('/js')}"> <a href="/js">JAVASCRIPT</a> </li> </ul> </div> <div ng-view></div> <script> function HeaderController($scope, $location) { $scope.isActive = function(viewLocation) { return viewLocation === $location.path(); }; } </script> </body> </html> Output: Method 2: Here we will use the modular function in Angular JS to create a module. A module is created by using the AngularJS function angular.module. Syntax: for creating a module: <div ng-app="myFirstApp">...</div> <script> var app = angular.module("myFirstApp", []); //myFirstApp refers to HTML element in which application runs. </script> Syntax: for adding a directive to the module: <div ng-app="myApp"></div> <script> var my_app = angular.module("myFirstApp", []); my_app.directive("DirectiveApp", function() { return { template : "Hello Geeks!!!" }; }); </script> Example 2: This is another example that describes setting the active tab style using AngularJS. HTML <!DOCTYPE html> <html> <head> <title>How to set active tab style with AngularJS?</title> </head> <body> <div ng-app="link"> <a href="#Geeks For Geeks" active-link="active"> Geeks For Geeks </a> <a href="#HTML" active-link="active">HTML</a> <a href="#JAVASCRIPT" active-link="active">JAVASCRIPT</a> </div> <script> angular.module('link', []).directive('Link', ['$location', function(location) { return { link: function(scope, element, attrs) { var active = attrs.activeLink; var path = attrs.href; path = path.substring(1); scope.location = location; scope.$watch('location.path()', function(newPath) { if(path === newPath) { element.addClass(active); } else { element.removeClass(active); } }); } }; }]); </script> </body> </html> Output: Comment More infoAdvertise with us Next Article How to set active tab style with AngularJS ? atharvapaliwal7 Follow Improve Article Tags : JavaScript Web Technologies AngularJS AngularJS-Questions Similar Reads How to Set navbar active class with Bootstrap and AngularJS ? In this article, we will see how to set the navbar active class with Bootstrap and AngularJS, & will know its implementation through the example. To accomplish this task, you can use ng-controller(NavigationController) to set the bootstrap navbar active class with AngularJS. To run a single cont 2 min read How to determine active route in AngularJS ? In this article, we will see how to determine the active route in AngularJS, along with understanding the basic implementation through the example. Approach: To determine which is the active route at any moment in AngularJS this can be achieved by using $on() & $location.path() method. An event 2 min read How To Set Width Of mat-table Column In Angular? In Angular Material, the mat-table component is a powerful data table tool that allows you to display data in a structured and flexible way. However, when it comes to customizing the appearance of the table, especially the width of individual columns, you may need to apply custom styling techniques. 4 min read How to Style an Active Link in VueJS ? In single-page applications effective navigation becomes crucial. In this article, we'll explore how to style active links in Vue.js using the popular routing library, Vue-router. Table of Content Using router-link-exact-active classConditional class bindingSteps to Setup the Project EnvironmentStep 4 min read How to check which tab is active using Material UI ? Material-UI is one of the most popular React UI libraries. Material-UI components work in isolation. They are self-supporting, and will only inject the styles they need to display. They don't rely on any global style-sheets such as normalize.css. Some examples of Material UI components are Dialog, T 3 min read How to Open URL in New Tab using Angular ? In this article, we will learn How to open a link in a new tab using Angular. A Link is a connection from one web page to another web page. Generally, the anchor tag can be used to open URLs in a new tab in an elementary and straightforward manner. However, the window.open() method can also be utili 2 min read Styling Active Router Link in Angular Styling the active router link in angular allows the user to differentiate between the active router link and inactive router links. Angular provides a special mechanism to work with active router links. Approach: Create the Angular app to be used.Create the header component that contains the navi 2 min read Semantic-UI Tab Active State Semantic UI is an open-source framework that uses CSS and jQuery to build great user interfaces. It is the same as a bootstrap for use and has great different elements to use to make your website look more amazing. Semantic UI offers a Tab component for users to bundle up different categories of con 3 min read How to set active class to nav menu from bootstrap? To dynamically set the active class on Bootstrap navigation menus based on scroll or click events, JavaScript is employed to track the web page's position. Functions are utilized to handle these events, ensuring the active class is applied to the relevant navigation sections accordingly.ApproachThe 3 min read How To Style Components Using Angular ngClass? Styling components effectively is important in web development, and Angular offers various ways to apply CSS to your components. One of the most powerful and flexible methods is using the ngClass directive. The ngClass directive allows you to dynamically add or remove CSS classes based on component 5 min read Like