Force UI update on model change

4,517 views
Skip to first unread message

Johan Steenkamp

unread,
Nov 18, 2011, 4:58:08 PM11/18/11
to ang...@googlegroups.com
I would expect that due to data binding this would just work but my UI does not update:

1. Form shows last updated timestamp, form data object (model) like this 

self.myform = { tsupdated : 1321652468906, ... other form model stuff ... }}

2. Change form and save, server turns saved form (for testing return entire model object, in practice would return limited items - say only timestamp).

3. I updated form data object in service callback

MyService.save( ..... , function(data){
   self.myform = data;
});

UI does not show returned updated timestamp. If I refresh browser it does.

Am I doing this wrong? How can I force UI update?

Misko Hevery

unread,
Nov 18, 2011, 11:29:08 PM11/18/11
to ang...@googlegroups.com
How exactly are you talking to the server? if you are using $xhr service it should just work. If you are doing something else you may need to kick angular by doing scope.$root.$eval();

Could you paste actual working code on jsfiddle.net?



--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/o3FHD4AttNEJ.
To post to this group, send email to ang...@googlegroups.com.
To unsubscribe from this group, send email to angular+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/angular?hl=en.

Johan Steenkamp

unread,
Nov 20, 2011, 1:36:58 AM11/20/11
to ang...@googlegroups.com
Thanks Misko

I improved/fixed my services code based on inputs to another forum question I had and now looks like its working as expected.

Good to know about scope.$root.$eval() anyway.


Misko Hevery

unread,
Nov 21, 2011, 1:21:14 PM11/21/11
to ang...@googlegroups.com
Glad that work.

BTW, in 0.10.x release it is scope.$apply(function(){ // do your work here });

-- Misko

--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To view this discussion on the web visit https://groups.google.com/d/msg/angular/-/TqIVpnsaccIJ.

Johan Steenkamp

unread,
Nov 21, 2011, 1:24:16 PM11/21/11
to ang...@googlegroups.com
Good to know - I have been working with 0.10.5.

Thanks
Reply all
Reply to author
Forward
0 new messages