0
使用離子創建器時,登錄/註銷時出現問題,我的側邊菜單信息(頭像,用戶名...)保留上一個用戶的信息(I在兩個帳戶之間切換以進行測試)。我不知道如何刷新或刪除與前一個用戶相關的所有信息,以便爲下一個用戶刷新我的側邊菜單。我可以在控制檯中看到加載了正確的值,但它們不會擦除菜單中的前一個值。登錄/註銷後無法刷新離子菜單上的數據
有什麼建議嗎?
這裏是我的代碼:
// SIGNOUT FUNCTION in the controller
$scope.signOut = function(){
firebase.auth().signOut().then(function() {
// This is to try to "clean" "clear" all informations of the previous user
$ionicLoading.show({
template: 'Logging out....'
});
$timeout(function() {
$ionicLoading.hide();
$ionicHistory.clearCache();
$ionicHistory.clearHistory();
$ionicHistory.nextViewOptions({
disableBack: true,
historyRoot: true
});
$state.go("connexion");
}, 30);
});
};
// MAJ DOM (menu) FUNCTION in the controller
// function used for refresh the menu informations (avatar, displayname...)
$scope.majDom = function()
{
//$state.reload();
var user = firebase.auth().currentUser;
var uid;
$scope.userData = user;
if (user !== null) {
$scope.userData.displayName = user.displayName;
$scope.userData.email = user.email;
$scope.userData.avatar = user.photoURL;
uid = user.uid;
//With these lines, I can read in the console that the right informations are loaded after a new login, but never appear in the menu, instead there are previous user's informations.
console.log("Avatar de l'user :", $scope.userData.avatar);
console.log("Nom de l'user :", $scope.userData.displayName);
console.log("Email de l'user :", $scope.userData.email);
}
}
// LOGIN FUNCTION in the controller
$scope.loginEmail = function($email, $password){
var alertPopup;
function signInSuccess(response) {
console.log('signInSuccess : ', response);
// This is to call a menu refresh, but dosen't work
$scope.majDom();
$state.go("menu.VNements");
}
firebase.auth().signInWithEmailAndPassword($email, $password)
.then(signInSuccess)
};
// MENU FUNCTION in the Menu Page of the creator
function ($scope, $stateParams, $state, $firebaseArray, $ionicHistory) {
//$ionicUser, $ionicAuth,
var user = firebase.auth().currentUser;
var uid;
$scope.userData = user;
$ionicHistory.clearCache();
$ionicHistory.clearHistory();
$ionicHistory.nextViewOptions({
disableBack: true,
historyRoot: true
});
if (user !== null) {
$scope.userData.displayName = user.displayName;
$scope.userData.email = user.email;
$scope.userData.avatar = user.photoURL;
uid = user.uid;
console.log("Avatar de l'user :", $scope.userData.avatar);
console.log("Nom de l'user :", $scope.userData.displayName);
console.log("Email de l'user :", $scope.userData.email);
}
In the side menu's HTML the Avatar is called like this :
{{userData.avatar}}
And the display name :
{{userData.displayName}}
請,是任何人有一個想法? – Memphis