如果ui状态提供程序重定向到特定模板,并且我必须检查身份验证,如果其ng-switch-when = true需要重定向到仪表板
以下是我的状态提供程序配置。以下是我的mail.html。
点击主页我需要检查用户是否登录然后重定向到dashboard.html模板,是否可以在resolve方法中执行此操作?
angular.module('sample')
.config(function ($stateProvider) {
$stateProvider
.state('home', {
parent: 'site',
url: '/',
data: {
roles: []
},
views: {
'content@': {
templateUrl: 'scripts/app/main/main.html',
controller: 'MainController'
}
},
resolve: {
}
});
});
<div ng-cloak>
<div class="row">
<div class="col-md-12 text-center">
<h3>Welcome to Admin portal!</h3>
<div ng-switch="isAuthenticated()">
<div class="alert alert-success" ng-switch-when="true">
You are logged In.
</div>
<div class="alert alert-warning" ng-switch-when="false">
If you want to <a href="#/login">Login</a>
</div>
</div>
</div>
</div>
</div>
答案 0 :(得分:1)
是的,您可以在解决方案中应用相同的内容。在解析中定义函数isAuthenticated()并在那里检查你的条件并根据需要返回true / false。
angular.module('sample')
.config(function ($stateProvider) {
$stateProvider
.state('home', {
parent: 'site',
url: '/',
data: {
roles: []
},
views: {
'content@': {
templateUrl: 'scripts/app/main/main.html',
controller: 'MainController'
}
},
resolve: {
isAuthenticated : function () {
//get your condiion here for checking iff user is logged in
if(logged in )
return true
else
return false
}
}
});
});