I have a a angular factory class User which gets instantialted via a dynamic view filling in data from the view to the user variable which is then bound to the view.
I need to update the localstorage when ever there is a change to the userView.Name which is bound to the view input type='text' i.e. any change to the value in the text field directly changes the text in the user instance of the class and then updates the dynamic view which would update the localStorage ?
I have a sample of the code hosted at CodePen
Sample Code illustrating the problem
app.controller('TestController', ['$scope', 'Loki', 'MobileConstants', 'LocalStorageApi', 'User',
function ($scope, Loki, MobileConstants, LocalStorageApi, User, Book) {
LocalStorageApi.initialize();
var userData = LocalStorageApi.UsersView.data()[0];
var user = new User(userData);
$scope.userView = user;
}]);
app.factory('User', ['$rootScope', function ($rootScope) {
function User(userData) {
User.prototype.Name = userData.nameSample;
};
User.prototype = {
Name: null,
}
return User;
}]);
below is how the code would look like illustrating the problem