转移到子状态时,是否可以在顶级导航项上保持活动状态?

时间:2019-06-05 03:00:33

标签: angularjs angular-ui-router

我在自己的路线中针对子状态设置活动状态有困难:

    .state( 'sites', {
        url: '/sites',
        resolve: {
            auth: function resolveAuthentication( AuthResolver ) {
                return AuthResolver.resolve();
            }
        },
        templateUrl: 'app/components/sites/site.index.html',
        controller: 'SiteController',
        data: {
            requiresLogin: true,
        }
    })



    .state( 'sites.list', {
        url: '/list',
        resolve: {
            auth: function resolveAuthentication( AuthResolver ) {
                return AuthResolver.resolve();
            }
        },
        templateUrl: 'app/components/sites/site.list.html',
        controller: 'SiteListController',
        data: {
            requiresLogin: true,
        }
    })



    .state( 'sites.edit', {
        url: '/edit/:id',
        resolve: {
            auth: function resolveAuthentication( AuthResolver ) {
                return AuthResolver.resolve();
            },
            Site: ['$stateParams', 'SiteService',
                function( $stateParams, SiteService ) {
                    return SiteService.getOne( $stateParams.id );
                }],
            Locations: ['$stateParams', 'LocationService',
                function( $stateParams, LocationService ) {
                    return LocationService.get();
                }],
            SiteGroups: ['$stateParams', 'SiteGroupService',
                function( $stateParams, SiteGroupService ) {
                    return SiteGroupService.get();
                }]
        },
        templateUrl: 'app/components/sites/site.edit.html',
        controller: 'SiteEditController',
        params: {
            tab: 1
        },
        data: {
            requiresLogin: true,
        }
    })

我的导航是根据对象数组构建的:

    // Build the menu items
    $rootScope.menuItems = [
        {
            name: 'Dashboard',
            icon: 'fal fa-tachometer',
            url: 'home',
            authorisedGroups: ['Marketing'],
            divider: false,
            children: [],
            style: {},
            visible: true
        },
        {
            name: 'Sites',
            icon: 'fal fa-home',
            url: '',
            authorisedGroups: ['Marketing'],
            divider: false,
            children: [
                {
                    name: 'Maintenance',
                    icon: 'fal fa-edit',
                    url: 'sites.list',
                    visible: true
                },
                {
                    name: 'Site Groups',
                    icon: 'fal fa-chart-network',
                    url: 'siteGroups.list',
                    visible: true
                },
                {
                    name: 'Locations',
                    icon: 'fal fa-map-marker-alt',
                    url: 'locations',
                    visible: true
                }
            ],
            style: {},
            visible: true
        },
        ...

对于导航数组中的所有对象,使用以下命令可以使active状态正常运行:

ui-sref-active="active"

当我目前在sites.list中并且单击某个项目以导航到sites.edit时,会发生我的问题。我正在尝试针对active保持sites.list的状态。

示例,在sites.list中:

enter image description here

示例,当您单击列表项并移至sites.edit时:

enter image description here

这可能吗?

0 个答案:

没有答案