我在Firebase应用中工作,我需要在DOM中保留一些数据,一旦用户登录就可以看到用户名和电子邮件,但是一旦刷新页面,用户仍然会登录但是这些数据会从DOM中消失。
<div class="item">
{{::userDisplayInfo.name}}
</div>
<div class="item">
{{::userDisplayInfo.email}}
</div>
这里是JS
$scope.signIn = function (user) {
auth.$authWithPassword({
email: user.email,
password: user.pwdForLogin
}).then(function (authData) {
ref.child("users").child(authData.uid).once('value', function (snapshot) {
var val = snapshot.val();
$scope.$apply(function () {
$rootScope.name = val;
$scope.userDisplayInfo.name = $rootScope.name.displayName;
$scope.userDisplayInfo.email = $rootScope.name.email;
});
console.log(user);
});
}).catch(function (error) {
console.log(error);
});
};
那么,我应该怎么做才能在DOM中坚持用户和电子邮件?
答案 0 :(得分:2)
大多数现代浏览器都支持HTML5本地存储。首先,检查浏览器是否支持它:
string clmHeader = null;
int clmWidth = 0;
foreach (string s in List<T>())
{
clmHeader = s;
//Add an invisible label to your form
lbl.Text = s;
clmWidth = lbl.Width;
ListView.Columns.Add(clmHeader, clmWidth, HorizontalAlignment.Left)
}
然后设置你的数据,只需这样做:
if(typeof(Storage) !== "undefined") {
// localStorage is OK to use
} else {
// no localStorage support
}
请记住在注销时清除该值,因为即使在浏览器关闭并重新打开后,localStorage仍然存在。
答案 1 :(得分:1)
现在保持简单,使用$ cookies:
@property (nonatomic, retain) IBOutlet UITextField *Usernametxtbx;
@property (nonatomic, retain) IBOutlet UITextField *Passwordtxtbx;
然后验证用户是否已登录:
// $cookies injected somewhere above
$cookies.put('userEmail', $scope.userDisplayInfo.email');