Yes it is.  This is a very conventional scenario.

On Friday, March 13, 2015 at 2:49:12 AM UTC-4, Yavuz Bogazci wrote:
>
> Is such a problem not daily business? I mean in real world you have most 
> of the time a backend in form of a db and in case of angularjs local json 
> where you bind your your controls. 
>
> Am Freitag, 13. März 2015 02:38:56 UTC+1 schrieb Mo Moadeli:
>>
>> To repeat, your 'local' model is updated but the actual write to the db 
>> fails.  Question is: How does one set the 'local' model back to what it WAS 
>> (i.e. how does one keep the local model and db values tightly in sync?).
>>
>> There is the obvious answer, where you store/deep copy previous state to 
>> a local variable and restore the model if webservice fails (probably 
>> through a callback fail of the $http or db call).   Here are further 
>> thoughts from SO:
>>
>>
>> http://stackoverflow.com/questions/16915984/angularjs-restoring-model-value-in-watch-after-failed-update-on-server-side
>>  
>>
>> However, if you'd like to be adventurous, look at Angular's built in 
>> 'rollback' function for the model call ngModelOptions:
>>
>> https://docs.angularjs.org/api/ng/directive/ngModelOptions
>>
>> Hope this helps.
>>
>> On Thursday, March 12, 2015 at 3:44:27 PM UTC-4, Yavuz Bogazci wrote:
>>>
>>> Hi,
>>>
>>> i am calling a webservice which returns data in JSON format. I store 
>>> this into a variable called*myrecipes* and show these through rg-repeat 
>>> in a grid. This works fine! I have bound the database field to the checkbox 
>>> through ng-model. This works, too. Now my requirement:
>>>
>>> I could call a webservice function to update the current item in the 
>>> database through ng-change. When the call is successfull the model gets 
>>> updated and the value in the database is updated, too. Everything fine!
>>>
>>> BUT what if something goes wrong when i try to update the value in the 
>>> database through the webservice? The model (the local data) is getting 
>>> updated but the value in the database not! That may not happen! How can i 
>>> prevent this? How could i perhaps catch a single item which was triggered 
>>> through the ng-change and set the value in the model back to the previous 
>>> value?
>>>
>>>

-- 
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.

Reply via email to