我想如果sessionStorage.logged设置为true,以我的页面重定向到主页。下面是我的code。为什么我的低于code是行不通的。
由于我是新来angularjs我不知道怎么了这一点。我会更加心存感激到u如果u有助于解决这个
。当('/登录,{ templateUrl:意见/ login.html的, 控制器:'LoginCtrl', 解决: { 乱:功能() { VAR T =(sessionStorage.logged)的ToString(); 如果(T ==真) { redirectTo:'/家; } } }})
解决方案
使用 $ location.path()
,它的工作原理就像 redirectTo
:
。当('/登录,{ templateUrl:意见/ login.html的, 控制器:'LoginCtrl', 解决: { 乱:函数($位置) { VAR T =(sessionStorage.logged)的ToString(); 如果(T ==真) { $ location.path('/家); // redirectTo:'/家; } } }})
I want to redirect mypage to home page if sessionStorage.logged is set to true. Below is my code. why my below code is not working.
Since i am new to angularjs i dont know how to this. I will be more thankfull to u if u help to solve this
.when('/login',
{
templateUrl: 'views/login.html',
controller:'LoginCtrl',
resolve:
{
mess:function()
{
var t=(sessionStorage.logged).toString();
if(t=="true")
{
redirectTo: '/home';
}
}
}
})
解决方案
Use $location.path()
, it works just like redirectTo
:
.when('/login',
{
templateUrl: 'views/login.html',
controller:'LoginCtrl',
resolve:
{
mess:function($location)
{
var t=(sessionStorage.logged).toString();
if(t=="true")
{
$location.path('/home');
//redirectTo: '/home';
}
}
}
})