以我的角度隐藏特定页面的标题 [英] header hide for a particular page in my angular

查看:26
本文介绍了以我的角度隐藏特定页面的标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理 angular 项目,我需要仅在登录页面上隐藏标题块.我试图隐藏登录页面上的标题.但它仍然对我不起作用.谁能帮我在登录状态下隐藏它.

这里是我的索引 html

<div ng-include src="'views/header.html'" ng-hide="$state.current.name === '登录'"></div><div class=""><div ui-view></div>

这里是我的 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('基础', {摘要:真实,网址:'',templateUrl: 'views/base.html'}).state('登录', {网址:'/登录',父母:'基地',templateUrl: 'views/login.html',控制器:'LogCt'}).state('坝', {网址:'/坝',父母:'基地',templateUrl: 'views/dam.html',控制器:'DamCt'})});

解决方案

您无法直接在 HTML 上访问 $state 对象.要访问它,您应该将 $state 对象与 $scope/$rootScope 放在一起,您可以在 run 块/controller &使用 $state.includes 而不是 $state.current.name

标记

代码

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

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


  });

解决方案

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

这篇关于以我的角度隐藏特定页面的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆