1

I am sending a normal get request as follows which was working normally:

service.show = function (slug) {
            console.log(slug)
            return $http.get('api/packages/'+slug, slug).success(function(response){
                service.package = response.package;
            });
        };

Suddenly after I started combining all js files together using gulp I get this weird error:

angular.js:10147 TypeError: Cannot create property 'method' on string 'package-38'

Since the application is an api so I tried to run the request using postman to see if it's working and it was. However when the same request is called in a certain page, I get this error.

I check variable slug which is a string and it is sent normally, so what could be the possible bug here?!

1 Answer 1

2

The second parameter $http.get expects, is an object with http request configuration.

Have a look at angular documentation. See the Shortcut methods section.

$http.get('/someUrl', config).then(successCallback, errorCallback);

Or better and readable call looks like below:

$http({
  method: 'GET',
  url: 'api/packages/'+slug
}).then(function(response){
            service.package = response.package;
        }, function errorCallback(response) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
Sign up to request clarification or add additional context in comments.

Comments

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.