我在离子骨架和localstorage cordova之间存在兼容性问题, 事实上,当我在输入文本登录中获取本地存储时,我的应用程序没有检测到输入中有一些文本。
但是,如果我点击输入删除一个字母并输入一个字母,我的控制器会检测到文本。
请有人可以帮助我吗?
HTML:
<form name="form" class="padding">
<label class="item item-input">
<input ng-model="login.username" type="text" name="username" id="username" placeholder="Utilisateur" required>
</label>
<label class="item item-input">
<input ng-model="login.password" type="password" name="password" id="password" placeholder="Mot De Passe" required>
</label>
<div class="padding">
<button class="button button-block button-outline button-assertive" ng-click="login()" ng-disabled="form.$invalid">Se Connecter</button>
</div>
</form>
Controller.js
$scope.login = function (username, password) {
Chats.login($scope.login).then(function (data) {
if (Object.keys(data.data).length === 1) {
window.localStorage.setItem("username", $scope.login.username);
window.localStorage.setItem("password", $scope.login.password);
console.log($scope.login.password);
$ionicHistory.nextViewOptions({
disableBack: true
});
$state.go('app.accueil');
} else {
$ionicPopup.alert({
title: "Erreur",
template: "Verifiez Utilisateur et Mot De Passe",
okText: 'Ok',
okType: 'button-positive'
});
}
})
}
app.js
$ionicPlatform.ready(function () {
document.getElementById('username').value = window.localStorage.getItem("username");
document.getElementById('password').value = window.localStorage.getItem("password");
答案 0 :(得分:1)
为什么不使用范围将保存的值分配给输入字段:
$scope.login.username = window.localStorage.getItem("username") ? window.localStorage.getItem("username") : "";
$scope.login.password = window.localStorage.getItem("password") ? window.localStorage.getItem("password") : "";
如果我是你,我会检查这些值是否总是字符串:
console.log(window.localStorage.getItem("username")); // => "Username"
console.log(window.localStorage.getItem("password")); // => "Password"
否则也可能存在问题。