Angular Add and remove Active class on click ng toggle

Angular Add and remove Active class on click ng toggle

Today, We want to share with you Angular Add and remove Active class on click ng toggle.
In this post we will show you How to Add and remove active class on click using AngularJS, hear for Add Class, Remove Class or Toggle Class to div using AngularJS we will give you demo and example for implement.
In this post, we will learn about Add or Remove css class to HTML element in angularJS with an example.

angular active class on click

see I have step by step explained (Add active class to an active element append class) about adding a new active class on click button and change.

READ :  Angular 4 CRUD Operation MVC - Angular 4 insert update delete

But if we need to change nav menu to remove the active class on button clicking the item again more times.
now Let us check and easy ro understand how it will work.

The web app used to app header and app footer of an application basic need are typically outside the angularjs scope of all the content or angularjs controller you are working on.
This makes active class menu and managing the navigation different state a little more to challenging.

In my apps case, to managing active class to navigation state is add class to simply applying an active class to nav menu a particular element.

READ :  Angular Arithmetic Operations BODMAS Rule

E-junkie: Sell digital downloads online

E-junkie Provides a Copy-paste buy-now, and cart buttons for selling downloads, codes and tangible products on any website, blog, social media, email and messenger!

Also see:

  1. The Top 10+ Best Webinar Software Platforms For 2020-2021
  2. Build Your Future Godaddy Careers And Jobs
  3. Introduction To Web Hosting Services

  <title>angularjs menu active class</title>

<div class="account-item">
<div class="account-heading">
<h4 class="account-title">
        <a href="#/NavMessagesDisplay"> {{ navitem }}</a>

angular active class on click File Name : app.js

var navapp = angular.module('navmenuapp', []);
navapp.controller('navmenuMainCtrl', function($scope) {
 $scope.listmenuItemsdata = ['Home','Tools','About Us','Services','Portfolio','Contact', 'Products', 'Other','Download'];
$scope.navmenuactiveMenu = $scope.listmenuItemsdata[0];
   $scope.navsetActivemenu = function(navmenuItemname) {
    $scope.navmenuactiveMenu = navmenuItemname


/* include or Put your css in here style.css file */

.active {
  background : red;

Alternate Way Simple – angular active class on click

A very Simple and elegant – esay way is to use angularjs ng-controller to run a single controller used to outside of the ng-view data changes:

<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
		//List of Navigation menu in li html tag
<li><a href="/">Home</a></li>
<li><a href="/AboutUs">AboutUs</a></li>
<li><a href="/Services">Services</a></li>
<li><a href="/PORTFOLIO">PORTFOLIO</a></li>
<li><a href="/Products">Products</a></li>
<li><a href="/Career">Career</a></li>
<li><a href="/Contact">Contact</a></li>
<li><a href="/Tools">Tools</a></li>
<li><a href="/Privacy">Privacy</a></li>
<li><a href="/Terms">Terms</a></li>

and specific path to include in controllers.js:


function NavHeaderMenuController($scope, $location) 
    $scope.navisActiveMenu = function (setviewLocationname) { 
        return setviewLocationname === $location.path();