1

I want to pass a domain name as parameter with $resource request. I tried this but it doesn't work. I don't see why. Any clue ? It outputs http://:url/ instead of the variable I'm trying to pass.

edit: the variable :url passes if I do something like this : http://adomain.com/:url

Here's my code :

My factory :

angular.module('myApp')
  .factory('LoadingContent', function LoadingContentFactory($resource) {
    return $resource('http://:url/wp-json/posts/?type[]=:type&filter[posts_per_page]=50&filter[order]=DESC', {type: '@type',url: '@url'}, {'get': {method: 'GET', isArray: true, params: {type: '@type',url: '@url'} }});
  });

My function :

LoadingContent.get({
    url : $scope.selectedCompany.URL,
    type : $scope.selectedCompany.type,
})
.$promise.then(
    function(data){
        $scope.articles = data;
        openInfoModals.closeModal();
    }
);

Problem solved : The problem comes from the version of angular-resource#1.4.5. I went back to 1.4.3 version and it works.

If anyone has a solution to make it work with 1.4.5, he's welcome.

2 Answers 2

1

The real issue stems from adding support for IPv6 URLs in ngResource (see https://github.com/angular/angular.js/issues/12512). If you take a look at the commit, they effectively ignored the domain/hostname when doing parameter replacement. As mentioned, downgrading to 1.4.3 fixes the issue. Fortunately, that seems to be the only change between 1.4.3 and 1.5.5, so downgrading isn't too much of a problem.

For completeness, I also created this issue in the angular project to track a permanent fix for it: https://github.com/angular/angular.js/issues/14542.

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

Comments

0

I don't think there is any thing wrong in your code.

I have created a plunker replicating your code and its working fine.

Here is its link : http://plnkr.co/edit/RsI3TgKwcjGEXcTMKoQR?p=preview

3 Comments

It outputs this error : XMLHttpRequest cannot load http://:url/wp-json/posts/?type[]=publication&filter[posts_per_page]=50&filter[order]=DESC. As you can see :type => Publication but :url doesn't pass. That's weird.
did you check the plunker ..i don't get the error for me its working good
Problem solved : The problem comes from the version of angular-resource#1.4.5. I went back to 1.4.3 version and it works. Thank you.

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.