Angularjs包含在除

时间:2016-02-03 09:05:54

标签: html angularjs

我想在所有内页上包含我的标题,但不要在登录注册和&登录后出现的另一个页面。 这是我的HTML代码:

<div class="wrapper">
        <div ng-if="$root.user" ng-include="'modules/partials/header.html'"></div>
        <div class="view" ui-view></div>
    </div>

因为在内部设置了$ rootScope.user的值,所以它显示了标题。

我该怎么办?

2 个答案:

答案 0 :(得分:0)

最初保留$rootScope.user = false 在您不想显示标题的所有页面上,您可以设置$rootScope.user = true

答案 1 :(得分:0)

您还可以使用多个视图:

<header ui-view="header"></header>
<div ui-view></div>
$stateProvider

// bare abstract state, only fills the unnamed view
.state("bare", {
  abstract: true,
  views: {
    "@": {
      template: "<div ui-view></div>"
    }
  }
})

// full abstract state, fills both header view and unnamed view
.state("full", {
  abstract: true,
  views: {
    "header@": {
      template: "<h1 ng-bind='header.title'></h1>",
      controller: "HeaderController as header"
    },
    "@": {
      template: "<div ui-view></div>"
    }
  }
})

// login state, inherits from bare state
.state("login", {
  parent: "bare",
  url: "/login",
  template: "...",
  controller: "..."
})

// home state, inherits from full state
.state("home", {
  parent: "full",
  url: "/home",
  template: "...",
  controller: "..."
})

http://plnkr.co/edit/dsikxeR1cg1Xl1wgufNw