加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 如何在整个页面上显示ui-router状态?

发布时间:2020-12-17 17:53:54 所属栏目:安全 来源:网络整理
导读:我正在使用ui-router进行状态处理.这工作正常,但现在我必须创建页面404,并希望在整个页面上显示它,而不是像其他页面一样在页面内显示. app.config(['$stateProvider','$urlRouterProvider','$locationProvider',function ($stateProvider,$urlRouterProvider
我正在使用ui-router进行状态处理.这工作正常,但现在我必须创建页面404,并希望在整个页面上显示它,而不是像其他页面一样在页面内显示.

app.config(['$stateProvider','$urlRouterProvider','$locationProvider',function ($stateProvider,$urlRouterProvider,$locationProvider) {

        $locationProvider.hashPrefix('!').html5Mode({
            enabled: true,requireBase: false
        });

        $stateProvider
        .state('stateIndex',{
                    url: '/',templateUrl: '/templates/list.html',controller: 'dashListController'     
        })
        .state('stateList',{
                    url: '/list',controller: 'dashListController'
        }).state('stateDashboard',{
                    url: '/dashboard/:id',templateUrl: '/templates/dashboard.html',controller: 'dashboardController'
        })
        .state('stateWidgetsList',{
                    url: '/widgetsList',templateUrl: '/templates/widgetsList.html',controller: 'widgetsListController'
        })
        .state('404',{
            url: '/404',templateUrl: '/templates/404.html'
        });
}]);

在我的index.html上我有

<div ui-view></div>

在我显示所有页面的地方,除此之外我还有标识,菜单等.我想在显示404页面时隐藏它.

我该怎么做?

解决方法

我个人会重新设计index.html,并将外部模板(徽标,菜单等)带入其自己的模板和状态.然后,您可以在ui-router层次结构中将子状态置于其下方.例如:

$stateProvider
    .state('app',{
                abstract: true,url: '',templateUrl: '/templates/appcontainer.html'
    })
    .state('app.stateIndex',{
                url: '/',controller: 'dashListController'     
    })
    .state('404',{
        url: '/404',templateUrl: '/templates/404.html'
    });

然后你只需要将你的标识/菜单等放在appcontainer.html中,然后只需要一个< div ui-view>< / div>在你的index.html里面.此外,如果您这样做,请不要忘记在appcontainer.html中添加子ui-view.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读