I have base model as service which store the content into the localstorage (stackoverflow example, mine is almost the same):
app.factory('userService', ['$rootScope', function ($rootScope) {
var service = {
model: {
name: '',
email: '',
"testArray": [
{
"first": 1,
"second": 2,
"third": "abc"
},
{
"first": 4,
"second": 5,
"third": "xyz"
}
]
},
SaveState: function () {
sessionStorage.userService = angular.toJson(service.model);
},
RestoreState: function () {
service.model = angular.fromJson(sessionStorage.userService);
}
}
$rootScope.$on("savestate", service.SaveState);
$rootScope.$on("restorestate", service.RestoreState);
return service;
}]);
Now, I have ng-repeat with input type text on each repeat and has ng-model respectively.
I'm trying to capture these ng-models in the above base model as ARRAY(not object) and then, store the object model in the localstorage.
How can I store ng-repeat array in the localStorage? Will the current approach work?
Thank you.