【发布时间】:2015-10-11 03:22:34
【问题描述】:
在一个简化的场景中,我有两个 UI-Router 状态,并希望它们具有不同的主体背景颜色。
理想情况下,我想做以下事情:
<body ng-class="background" ui-view>
</body>
然后在控制器中为状态设置背景类(可能是动态的,意思是:在控制器中计算):
stateHelperProvider
.state({
name: 'a',
url: '/a',
templateUrl: 'views/a.html',
controller: function ($scope) {
$scope.background = 'bg1';
}
})
.state({
name: 'b',
url: '/b',
templateUrl: 'views/b.html',
controller: function ($scope) {
$scope.background = 'bg2';
}
});
但是将ui-view 属性放在主体上会删除它。所以我必须把ui-view属性放在body里面的一个div上。
<body>
<div ui-view></div>
</body>
我现在如何控制身体背景?
我知道各种 hack(例如,在 UI-Router 的 onEnter 函数中访问 body 的类 DOM 属性,...),但是有没有好的方法呢?
或者这一切都是为了让div[ui-view] 全高(即not trivial)并在这个元素上设置背景以模仿如何应用background on the body takes up the full viewport?
【问题讨论】:
标签: css angularjs angular-ui-router