0

I want to call v = "'"+u+"'" value into post method and i declared them as global variable. I'm not able to console those values outside get method. It's throwing me error. How to fix this ?

scope.Ex = function() {
            var u,w,v,c,is;

            $http.get("/api/patients/")
            .then(function(response) {
                scope.content = response.data;
                c = scope.content;
                is =c["0"].patient_ID;
                u = '/api/patients/'+is+'/';
                v = "'"+u+"'"

            });

            console.log(v);
            $http.post("/api/exams/",
                        {
                            patient_ID : v // I want to call V here from get method
                            // patient_ID : "/api/patients/1/"
                        })
                        .error(function(err){

                            //console.log(err);
                        })
                        .success(function(response) 
                        {
                            //console.log(v);
                            //console.log("Success")
                            //console.log(response);
                            //$scope.usersData = response;
                        });
        };
2

1 Answer 1

0

Chain the GET and POST operations:

$http.get(url)
  .then(function(response) {
    return response.data;
}).then(function(data) {
    return $http.post(url,data);
})

It is imortant to return data and promises to the handler functions.

For more information, see AngularJS $q Service API Reference - Chaining promises.

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

1 Comment

Thanks. Will go through that

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.