Bha*_*jan 4 javascript angularjs angularjs-routing angular-ui-router
我正在开展角度项目,我的需求只是登录页面上的隐藏标题块.我试图在登录页面上隐藏标题.但它仍然不适合我.你有没有人帮我在登录状态下隐藏它.
这里是我的索引html
<div ng-include src="'views/header.html'" ng-hide="$state.current.name === 'login'"></div>
<div class="">
<div ui-view></div>
</div>
Run Code Online (Sandbox Code Playgroud)
在这里我的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'
})
});
Run Code Online (Sandbox Code Playgroud)
您无法$state直接在HTML上访问对象.要获得对它的访问权限,你应该把$state对象放在$scope/ $rootScope,你可以在run块/ controller&使用$state.includes而不是$state.current.name
标记
<div ng-include src="'views/header.html'" ng-hide="$state.includes('login')">
</div>
Run Code Online (Sandbox Code Playgroud)
码
app.run(function($state, $rootScope){
$rootScope.$state = $state;
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3009 次 |
| 最近记录: |