ng-class to highlight active menu item based on ng-repeat. AngularJS

后端 未结 3 1680
眼角桃花
眼角桃花 2020-12-30 04:04

I have a menu based on the following example:

 
3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-30 05:01

    Try this out:- http://jsfiddle.net/uDPHL/146/

    This issue exists in older version of angular js Reference, issue got resolved after upgrading it to angular js 1.2.0 version.

    JS:-

    var navList = angular.module('navList', []);    
    
    navList.controller('navCtrl', ['$scope', '$location', function ($scope, $location) {
    
        $scope.navLinks = [{
            Title: 'home',
            LinkText: 'Home',
        }, {
            Title: 'about',
            LinkText: 'About Us'
        }, {
            Title: 'contact',
            LinkText: 'Contact Us'
        }];
    
        $scope.navClass = function (page) {
            var currentRoute = $location.path().substring(1) || 'home';
            return page === currentRoute ? 'active' : '';
        };   
    
    }]);
    

    HTML:-

    
    

提交回复
热议问题