I am trying to set a dynamic parameter in the $resources URLs.
I have found this helpful post, but sadly it hasn't solved my problem. THE cid's are still not filled in the $resource functions.
messageApp.factory('conversationService', function($http) {
var data = {cid: ''};
$http({method: "GET", url: '/myApp/resources/conversationwizard'}, {cache: true})
.success(function(d) {
data.cid = d;
})
.error(function(data) {
alert("Could not initiate conversation" + data);
});
return data;
});
messageApp.factory('messagesService', function($resource) {
return $resource('/myApp/resources/message/all', {}, {
query: {method: 'GET', isArray: true}
});
});
messageApp.factory('messageEventPoller', function($http, $timeout, conversationService) {
var data = {data: ''};
var poller = function() {
$http.get('/myApp/msgnotification?cid=' + conversationService.cid).then(function(r) {
data.data = r.data;
$timeout(poller, 1);
});
};
poller();
return data;
});
messageApp.factory('createMessageService', function($resource, conversationService) {
return $resource('/myApp/resources/message?cid=:cid', {cid: conversationService.cid}, {
create: {method: 'POST'}
});
});
messageApp.factory('messageService', function($resource, conversationService) {
return $resource('/myApp/resources/message/:id?cid=:cid', {cid: conversationService.cid}, {
show: {method: 'GET'},
update: {method: 'PUT', params: {id: '@id'}},
delete: {method: 'DELETE', params: {id: '@id'}}
});
});
Any pointers would be much appreciated.