0

This question is based in this previous answer.

I am trying to send an http request where one of the elements I want to send is expressed in the view as

{{selectedCountry.shipping[shippingType]}}

The request has to go along other element so in order to make a single request I mix them together with

$scope.checkoutData = angular.extend($scope.selectedCountry.shipping[$scope.shippingType], $scope.selectedCountry.name);

And then send the request with

$scope.submitForm = function() {
    $http.post('process.php', $scope.checkoutData)
};

But when doing the second step I get an error. You can see the working fiddle here (with the second step commented, so it doesn't break the code). Thanks in advance!

1 Answer 1

3

You need to inject $http to your controller:

app.controller('myCtrl', function($scope, $http) {
 ...
})

The error i see in your plunker is :

ReferenceError: $http is not defined

For your second issue with angular.extend, try changing your submit function to:

$scope.submitForm = function() {
    var checkoutData = {
        shippingAmount: $scope.selectedCountry.shipping[$scope.shippingType],
        country: $scope.selectedCountry.name
     }

    $http.post('process.php', checkoutData)
};
Sign up to request clarification or add additional context in comments.

2 Comments

That was missing, I have just fixed it :). But still then when I uncomment the expression it still gives an error jsfiddle.net/v3o87L5z
it seems like $scope.selectedCountry.shipping[$scope.shippingType] evalutes to a number which is 30. you cannot extend numbers only objects...

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.