0

Am wondering is it possible fetch data from an external api using ngresource in angularjs.`

var brk = angular.module('service', ['ngResource']);

brk.factory('ListingFactory', function ($resource) {
    return $resource("http://bonches.cloudapp.net/product/index", {}, {     
        query: { method: 'GET', isArray: true },
        create: { method: 'POST' }
    })
});

brk.factory('ListingsFactory', function ($resource) {    
    return $resource('http://bonches.cloudapp.net/product/index', {}, {    
        show: { method: 'GET' },
        update: { method: 'PUT', params: {id: '@id'} },
        delete: { method: 'DELETE', params: {id: '@id'} }
    })
});

when i run that it maps the url over the enviroment am working under like localhost:8000/http://bonches.cloudapp.net/product/index.

1
  • Check your config blocks for any $http request interceptors that might be changing your absolute urls. Commented Jan 25, 2016 at 10:42

1 Answer 1

1

You can only if your server implements CORS, a way to make a cross-site request based on HTTP headers.

Take a look here how to configure CORS: https://en.wikipedia.org/wiki/Cross-origin_resource_sharing

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you. I was able to enable CORS on the server but now how do i go about it in angularjs ?
client side (so in angular too) it should be transparent.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.