如何从get方法调用变量到post方法?
How to call variable from get method to post method?
我想将 v = "'"+u+"'"
值调用到 post 方法中,我将它们声明为全局变量。我无法在 get 方法之外控制这些值。这让我出错。如何解决这个问题?
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;
});
};
链接 GET 和 POST 操作:
$http.get(url)
.then(function(response) {
return response.data;
}).then(function(data) {
return $http.post(url,data);
})
对 return 数据和处理函数的承诺很重要。
有关详细信息,请参阅 AngularJS $q Service API Reference - Chaining promises。
我想将 v = "'"+u+"'"
值调用到 post 方法中,我将它们声明为全局变量。我无法在 get 方法之外控制这些值。这让我出错。如何解决这个问题?
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;
});
};
链接 GET 和 POST 操作:
$http.get(url)
.then(function(response) {
return response.data;
}).then(function(data) {
return $http.post(url,data);
})
对 return 数据和处理函数的承诺很重要。
有关详细信息,请参阅 AngularJS $q Service API Reference - Chaining promises。