2

I have following code: Html

<li ng-class="{ highlight: isActive('/admin/trackDef/list') || isActive('/admin/trackDef/add')}">
    <a href="${createLink(uri: '/#/admin/trackDef/list')}"></a>
</li>

Js controller

.controller('navCtrl', ['$scope', '$location', function ($scope, $location) {
    $scope.isActive = function (viewLocation) {
        return viewLocation === $location.path();
    };
    $scope.isAnyActiveAdmin = function () {
        return ['/admin/trackDef/list', '/admin/trackDef/add', '/admin/country/list','/admin/country/add', '/admin/user/list', '/admin/user'].indexOf($location.path()) > -1;
    };
}])

.config(['$routeProvider', function ($routeProvider) {
    $routeProvider.
        when('/admin/trackDef/list', {
            templateUrl: 'assets/trackDef/trackDef-list.tpl.html',
            controller: 'PaginatedListController',
            resolve: {Service: 'TrackDefServices'}
        }).
        when('/admin/trackDef/add', {
            templateUrl: 'assets/trackDef/trackDef-save.tpl.html',
            controller: 'TrackDefController'
        }).
        when('/admin/trackDef/:id', {
            templateUrl: 'assets/trackDef/trackDef-save.tpl.html',
            controller: 'TrackDefController'
        });
}])

How to highlight also pages with random address like:

/admin/trackDef/123 /admin/trackDef/234 /admin/trackDef/534

etc

mmacin
  • 111
  • 2
  • 11

1 Answers1

0

I think you can simplify things a bit and just use the JS function indexOf(), similar to how you're using it in isAnyActiveAdmin()

Your isActive() would look similar to this:

$scope.isActive = function () {
    return $location.path().indexOf("admin") ? true : false
};

This would then work for any path that includes admin.

EnigmaRM
  • 7,523
  • 11
  • 46
  • 72