角度jsに新しい。 ネストされたUIビューを実装していますが、ページの現在の状態をチェックするときに、$ state.currentを使用してng-showを設定できないようなオブジェクトが返されます。角度uiルータでnavbarネストされたビューを実装する
navbarが表示され、いくつかの州では。
私は、ユーザーがでログイン状態
上にあるときのようないくつかの州のために隠されたナビゲーションバーを希望
The main index.html page
<html>......
<body ng-app="myapp">
<nav ng-controller="headerCtrl" ng-show="shownav()" >
//here is the navbar code..The shownav is defined on the headerCtrl
</nav>
<div ui-view> </div>
//Angular js, controllers and services links
</body>
</html>
app.jsコード
var app = angular.module('myApp', ['ui.router']);
app.controller('headerCtrl',function($scope, $state) {
$scope.shownavbar = function(){
var state = $state.current;
if(state ==='login'){
return false;
}else{
return true;
}
}
app.config(function($stateProvider, $urlRouterProvider, $httpProvider){
$stateProvider
.state('login', {
url:'/login',
templateUrl: 'templates/index/login/login.html',
controller: 'loginCtrl'
})
.state('dash', {
url: '/dash',
templateUrl:'templates/layout/dashboard.html',
abstract:true
})
.state('dash.call',{
url: '/call',
templateUrl: 'templates/index/calls/calls.html',
controller: 'callCtrl'
})
.state('dash.profile', {
url: '/profile',
templateUrl: 'templates/index/account/profile/profile.html',
controller: 'profileCtrl'
})
});
を試してみました私も試しました
$scope.shownavbar = function(){
var state = $state.current;
$log.info(state);
}
これは、コンソールに返します。
angular.js:13708 Object {name: "", url: "^", views: null, abstract: true}
angular.js:13708 Object {name: "", url: "^", views: null, abstract: true}
angular.js:13708 Object {url: "/login", templateUrl: "templates/index/login/login.html", controller: "loginCtrl", name: "login"}
angular.js:13708 Object {url: "/login", templateUrl: "templates/index/login/login.html", controller: "loginCtrl", name: "login"}
angular.js:13708 Object {url: "/login", templateUrl: "templates/index/login/login.html", controller: "loginCtrl", name: "login"}
私はこれを解決するには、2つの方法で考えることができますPROBLEM
多分あなたが真か偽保存するために '$ rootScope'を使用し、'ラン() '使用のパスにすることができますが状態が変化しているときにそれを隠す関数。 –