我已经尝试了一段时间从这个调用中获取数据,但它总是返回“undefined”
httpCall = function(sTformName) {
let sURL = "https://urlthisone/api/",
response;
$http.get(sURL)
.success(function(data) {
response = data;
});
}
你知道我做错了什么吗?
提前谢谢。
最佳答案
你可以回来解决承诺…
httpCall = function(sTformName) {
let sURL = 'https://urlthisone/api/',
return $http.get(sURL);
}
httpCall('myForm').then(response => {
console.log(response.data);
});
$http.get
是一个异步调用,在这种情况下,必须通过解析返回的Promise关于javascript - 在AngularJS函数中调用$ http,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52338813/