简体   繁体   English

标题隐藏在我的角度中的特定页面

[英]header hide for a particular page in my angular

I m working on angular project and my need is hide header block on login page only. 我正在开展角度项目,我的需求只是登录页面上的隐藏标题块。 I tried to hide header on login page. 我试图在登录页面上隐藏标题。 But it still doesn't work for me. 但它仍然不适合我。 Can you any one help me to hide it on login state. 你有没有人帮我在登录状态下隐藏它。

Here my index html 这里是我的索引html

<div ng-include src="'views/header.html'"  ng-hide="$state.current.name === 'login'"></div>

    <div class="">
      <div ui-view></div>
    </div>

Here my app.js 在这里我的app.js

var app = angular.module('Qapp', ["ui.router", "ngRoute"])

app.config(function($stateProvider, $urlRouterProvider) {

    //$urlRouterProvider.when('/dam', '/dam/overview');
    $urlRouterProvider.otherwise('/login');

    $stateProvider
      .state('base', {
        abstract: true,
        url: '',
        templateUrl: 'views/base.html'
      })
        .state('login', {
          url: '/login',
          parent: 'base',
          templateUrl: 'views/login.html',
          controller: 'LogCt'
        })
        .state('dam', {
          url: '/dam',
          parent: 'base',
          templateUrl: 'views/dam.html',
          controller: 'DamCt'
        })


  });

You don't have access to $state object directly on HTML. 您无法直接在HTML上访问$state对象。 For get access to it you should put $state object with the $scope / $rootScope , You could do this in run block/ controller & use $state.includes instead of $state.current.name 要获得对它的访问权限,你应该使用$scope / $rootScope放置$state对象,你可以在run block / controller使用$state.includes而不是$state.current.name

Markup 标记

<div ng-include src="'views/header.html'"  ng-hide="$state.includes('login')">
</div>

Code

app.run(function($state, $rootScope){
   $rootScope.$state = $state;
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM