angularjs - How to configure Angular $resource (ngResource) to pull data from another domain using CORS -
i'd able setup resources using $resource using cors request data. i've got cors working $http same techniques don't apply $resource , hoping can come rescue , show me how $resource.
i've modified last step of angular tutorial use cors hacking phonecatservices service, in services.js file.
i found this example uses $http.defaults.usexdomain = true; delete $http.defaults.headers.common['x-requested-with'];line angular request data using cors if try $resource.defaults.usexdomain = true; error: "cannot set property 'usexdomain' of undefined".
i presume $resource doesn't have property, question is, how configure $resource make cross domain resource requests using cors.
here's code:
angular.module('phonecatservices', ['ngresource']). factory('phone', function($resource){ return $resource('http\\://localhost\\:8080/:phoneid.json', {}, { query: {params:{phoneid:'phones'}, isarray:true} }); });
i following error when try make request: object #<resource> has no method 'push'
edit
i've tried setting $http , works of time, when call made resource query, in case phone.get(phoneid); seems throw above error.
calling code suspect causing error (from controllers.js step 11 angular tutorial):
function phonedetailctrl($scope, $routeparams, phone) { $scope.phone = phone.get({phoneid: $routeparams.phoneid}, function(phone) { $scope.mainimageurl = phone.images[0]; }); $scope.setimage = function(imageurl) { $scope.mainimageurl = imageurl; } }
if remove innards of above method code runs fine (without obtaining image website), don't understand why wouldn't work? have set $http service use cors should pass $resource apparently.
can shed light on it? (any working example code appreciated).
edit: 13/08/13
just visiting question aware, none of answers below have answered question, researching answer myself if spots , has answer i'd appreciate still.
edit: 06/09/13
currently looking project, seems allow i'm looking for: https://github.com/jpillora/xdomain
ok, solution i've found project xdomain: https://github.com/jpillora/xdomain
i accept may not suitable it's decent cross browser solution , whilst we're stuck ie<10 seems best solution. (i aware ie8 , ie9 provide partial support ie isn't full support , don't want have waste time doing work around ie).
thanks provided answers question.
Comments
Post a Comment