$resource callback?

1,790 views
Skip to first unread message

Jehu

unread,
Oct 6, 2011, 7:10:46 AM10/6/11
to AngularJS
Hi,

i can't find out how to get a callback when data loading from server
has finished.
I've found some ideas to use $defer, but this is not acceptable
because one can not know how long the timeout must be set.

Can anyone give a hint for this topic?
Thanks!

Jehu

Igor Minar

unread,
Oct 6, 2011, 11:58:31 AM10/6/11
to ang...@googlegroups.com
myResource.$get([params,] callbackFn);

/i


--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
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.


Witold Szczerba

unread,
Oct 6, 2011, 12:11:59 PM10/6/11
to ang...@googlegroups.com

I think your question is not about data loading, but initial template, is that right?
If so, the answer is that in Angular, one does write a directive or widget, put it on the template and it will be called by Angular in the right time.
If that's not clear, tell us your story,so we could help you figuring it out.

Regards,
Witold Szczerba

Witold Szczerba

unread,
Oct 6, 2011, 12:21:25 PM10/6/11
to ang...@googlegroups.com
Oh, now I see the subject, it is about $resource service.

Jehu

unread,
Oct 7, 2011, 3:26:36 AM10/7/11
to AngularJS
Thank you, i've tryed this, but now it works with an extra call of
self.$eval().
Seems to be a timing problem?

Here's my service:

angular.service('ResContacts', function($resource) {
var self = this;
return $resource(
'/contacts/:id',
{ id: '@_id' },
{
'save': { method: 'POST' },
'list': { method: 'GET', isArray: true },
'update': { method: 'PUT' },
'remove': { method: 'DELETE' }
}
);
}, { $inject:['$resource'], $eager:true });

And now it works like this in controller:

ResContacts.list(function(res) {
self.contacts = res;
self.$eval();
jQuery('#table-contacts').dataTable( {"aoColumns":
self.tblColumns} );
});

It works only with self.$eval() after setting self.contacts.
But it's ok, i think. Right?

Igor Minar

unread,
Oct 7, 2011, 1:35:36 PM10/7/11
to ang...@googlegroups.com
it works, but it's a hack.

you are mixing the presentation and business logic. whenever you reference the dom from your controller a kitty dies, that's why you need the extra eval. :-)

create a table widget a feed it with the data from the controller. that's the right way to deal with this.

/i

Jehu

unread,
Oct 8, 2011, 4:31:35 AM10/8/11
to AngularJS
Thank you Igor,
i will create a widget. No kitty should die for me. :-D
Reply all
Reply to author
Forward
0 new messages