model = {
firstObj: {
a: '',
b: '',
c: '',
d: {
x: 0,
y: 0,
z: 0
}
},
secondArray: [
{
some: '',
thing:''
}
],
}
The model that I want to save on localstorage looks something like the
above object.
Now, the "secondArray" is what goes to ng-repeat. Every ng-repeat has input
field with ng-model "thing". Now, when all the "things" are filled and you
do a console log, I get the model with only 1 array. (length of array = 1).
The array is being over written with the last value. (ng-repeat has more
than 10 entries). What am i doing wrong?
On Thursday, March 20, 2014 9:14:40 PM UTC-7, tonypee wrote:
>
> ng-reapeat will iterate over any object or array. How you store, hydrate,
> modify, load, save, this in the model is up to you. As long as you remember
> to call $scope.$apply after an async operation that is performed outside of
> angular, then it should be reflected in the ng-repeat.
>
> So yes, you can save/load data to localStorage, and if you replace your
> model that is referenced by the ng-repeat, it should update.
>
> is this what your asking?
>
>
>
> On 20 March 2014 20:18, Srikar Shastry <[email protected]
> <javascript:>>wrote:
>
>> Hello,
>> 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.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "AngularJS" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected] <javascript:>.
>> To post to this group, send email to [email protected]<javascript:>
>> .
>> Visit this group at http://groups.google.com/group/angular.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> Tony Polinelli
>
>
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.