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.






MO MOADELI
FOUNDER & CEO
(c) 917 952 1964 | [email protected] | @credaciousmo
<https://twitter.com/credaciousmo>
www.credacious.com
T H E   C R E D I B L E  W E B

On Thu, Mar 12, 2015 at 3:44 PM, Yavuz Bogazci <[email protected]>
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.
>

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