質問

I started using Restangular to send RESTful requests from my AngularJS app. I have a REST service deployed on http://localhost:20080/v1/customer which produces JSON with customer information.

When I debug AngularJS app it hits a breakpoint in the back-end REST service, however in the browser console it always logs "Failed to find customers with status code 0". Moreover, I never hit the breakpoint in the function that I register as setResponseExtractor.

I also don't see any errors in the console.

When I open http://localhost:20080/v1/customer in the browser I get the following response:

[{"customerInfo":{"name":"My Name","email":"My Email"},"id":"6ca43d0f-94a8-36e8-af3d-963584573d6d"}]

My Restangular code is as follows:

var customerModule = angular.module('customer-module',
            ['restangular' ]).config(
            ['RestangularProvider', '$httpProvider',
                function (RestangularProvider, $httpProvider)
                {
                    RestangularProvider.setBaseUrl('http://localhost\\:20080/v1');
                    RestangularProvider.setResponseExtractor(function (response, operation, what) {
                      return response;
                    });
...

customerModule.controller('CustomerCtrl',
    [ '$scope', 'Restangular', function ($scope, Restangular)
    {
    var baseCustomers = Restangular.all("customer");
    $scope.customers = baseCustomers.getList().then(function (result) {
        console.log("Got customers", response.status);
    }, function (response) {
        console.log("Failed to find customers with status code", response.status);
    });

Thoughts?

役に立ちましたか?

解決 2

The problem turned out to be with accessing REST services running on a different port than my AngularJS app.

I am moving this thread to AngularJS mailing list - "Problems with a basic $resource.get() call"

Alec

他のヒント

I'm the creator of Restangular.

You also don't have to add the responseExtractor to the config if you're just returning the response. That's what it does by default.

If you have any other problem, please contact me!

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top