当我点击退出按钮时,它改变了状态,但没有刷新页面,因此,我的登录页面文本框仍然输入了数据。如果我使用新数据登录,则属性详细信息http请求不会提取新数据。 我试过,$ location.path,$ state.go但没用, 任何人都可以帮助我。
登录控制器
.controller('LoginCtrl', function($scope, $rootScope, AuthenticationService,ClientDetails, $ionicPopup, $state) {
$scope.data = { clientId: '', lastName: '', email: ''};
$scope.login = function () {
AuthenticationService.Login($scope.data.clientId, $scope.data.lastName, $scope.data.email, function(response) {
if(response.success) {
ClientDetails.setDetails(response.data);
$state.go('app.home');
console.log(response);
} else {
$scope.error = response.message;
var alertPopup = $ionicPopup.alert({
title: 'Login failed!',
template: $scope.error
});
}
});
};
})
通过服务获取属性:
.factory('PropertyDetails',
['$http', '$rootScope',
function ( $http, $rootScope) {
var clientId = $rootScope.globals.clientDetails.ClientId;
var service = {};
service.getProperties = function(callback){
$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded";
var data = ''; var status = ''; var message = '';
var response = {};
var Request = $http({
method: 'GET',
url: 'http://example.com/'+clientId,
data: data
})
Request.success(function(jdata, headers) {
if( headers === 200 ){
if(typeof jdata == 'object'){
status = jdata.Status;
message = jdata.Message;
data = jdata.Data;
$rootScope.globals.properties = data;
}else{
status = false;
message = "Response data is not a object!";
}
}else{
status = false;
message = "Something went wrong!";
}
//response = { success : status, message : message, data: data };
response = { success : status, message : message, data: $rootScope.globals.properties };
callback(response);
//callback($rootScope.globals.properties);
})
Request.error(function(data, headers){
if(typeof data == 'object'){
message = data.Message;
}else{
message = "Client not found.";
}
response = { success : false, message : message };
callback(response);
});
};
service.clearDetails = function(){
$rootScope.globals.properties = {};
};
return service;
}])
我的退出控制器:
.controller('menuCtrl', function($scope, $rootScope, ClientDetails, PropertyDetails,$timeout,$ionicHistory, $state,$location){
$scope.logOut = function(){
ClientDetails.clearDetails();
PropertyDetails.clearDetails();
$timeout(function () {
$ionicHistory.clearCache();
$ionicHistory.clearHistory();
$ionicHistory.nextViewOptions({ disableBack: true, historyRoot: true });
$state.go('login');
}, 30);
}
})
谢谢
答案 0 :(得分:0)
如果你想再次重新加载你使用过的数据,很多方法可以首先清除文本框控制器调用一次加载离子
$scope.$on('$ionicView.enter', function() {
//here some code
});
上面的代码当你打开页面时这个代码每次都在运行[load controller]。 它的简单方法。