I am using AngularJS 1.5 and ngResource. I have an array of objects, each object containing an IP address that I would like to send HTTP GET requests to in iteration. For example:
var arr = [{ip: '127.0.0.1', name: 'myHost'},{ip: '1.2.3.4', name: 'differentHost'}]
arr.forEach(function (obj) { // Send requests to obj.ip });
If i use $http service and just concatenate the IP address, it works fine. However, I want to use $resource service because I have a set of actions, but when i use the $resource to do so, it doesn't consider my host name/IP address as parameter.
var Host = $resource('http://:ip:49221/:action', { ip: '@ip' }, {
status: {method: 'GET', params: {action: 'currentStatus'} }
});
Host.status({ip: '1.2.3.4'}).$promise.then(function (res) {
console.log(res);
});
I get: XMLHttpRequest cannot load http://:ip:49221/currentStatus
Plunker: http://plnkr.co/edit/d9roMDWEbPpyG5upKSrv?p=preview
Am I doing something wrong?
Thanks
On XMLHttpRequest by definition you cannot do cross domain request but there is some lead you can explore.
How to configure Angular $resource (ngResource) to pull data from another domain using CORS
Is it Angular $http.defaults.useXDomain really neccessary in CORS?
And be careful there are some issues on ie8/9 : https://github.com/angular/angular.js/issues/2956