header hide for a particular page in my angular

2019-06-28 02:03发布

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

<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

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'
        })


  });

1条回答
2楼-- · 2019-06-28 02:26

You don't have access to $state object directly on HTML. 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

Markup

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

Code

app.run(function($state, $rootScope){
   $rootScope.$state = $state;
})
查看更多
登录 后发表回答