I'm starting with AngularJS and have my first problem with it.
How can I bind or save username and password in the localStorage? My form is empty after reloading the page or restarting the app.
I'm using this plugin: https://github.com/grevory/angular-local-storage
HTML:
<input type="text" name="cy_username" id="cy_username" ng-model="username">
<input type="password" name="cy_password" id="cy_password" ng-model="password">
<button class="button button-block button-positive icon ion-edit icon-left" ng-click="saveSettings()">Einstellungen
speichern
</button>
<button class="button button-block button-assertive icon ion-trash-b icon-left" ng-click="resetSettings()">
Einstellungen löschen
</button>
Controller:
angular.module('starter.controllers', ['LocalStorageModule'])
.controller('SettingsCtrl', function ($scope, localStorageService) {
$scope.username = localStorageService.get('username');
$scope.password = localStorageService.get('password');
$scope.saveSettings = function () {
if (localStorageService.isSupported) {
localStorageService.set('username', $scope.username);
localStorageService.set('password', $scope.password);
} else {
console.error('localStorage is not supported!');
}
};
// doesn't work, nothing happens
$scope.resetSettings = function () {
$scope.username = '';
$scope.password = '';
localStorageService.clearAll();
};
});
localStorageService.cookie.clearAll?saveSettings(andresetSetitngs) functions?