这里我写了简单的角度Roution Like
<li><a ui-sref="Login()">Login</a></li>
<li><a ui-sref="Logout()" ng-show="!usersessionData">Logout</a></li>
MyApp.js
var app = angular.module('MyApp', ['ui.router'])
app.config(function ($stateProvider, $urlRouterProvider, $httpProvider) {
$stateProvider
.state('Login', {
templateUrl: '/Kpmg/Homepages/LoginPages/Login.html',
controller: 'LoginCtrls'
})
当我登录时登录其重定向我2登录页面,当我成功提交我的凭证时,登出应该是可见的。
LoginCtrl.js
$scope.usersessionData = false;
$scope.SaveData = function (user) {
var obj = { 'UserName': user.Email, 'password': user.psw, 'grant_type': 'password' }
Login_Fac.GetLogin(obj).then(function (response) {
User_Session.SetCurrentUser(response.data);
$scope.usersessionData = true;
我需要使用usersessionData
来控制<li><a ui-sref="Logout()" ng-show="!usersessionData">Logout</a></li>
我的注销
答案 0 :(得分:0)
试
$rootScope.usersessionData = false;
$scope.SaveData = function (user) {
var obj = { 'UserName': user.Email, 'password': user.psw, 'grant_type': 'password' }
Login_Fac.GetLogin(obj).then(function (response) {
User_Session.SetCurrentUser(response.data);
$rootScope.usersessionData = true;
}
}
并且在定义了saveData函数的控制器中,注入$ rootScope,例如:
myApp.controller('LoginCtrls', function($scope, $rootScope) {
$rootScope.usersessionData = false;
$scope.saveData= ...;
});