我正在尝试将this.data
更改为API返回的结果,但似乎我无法实现此目的。我很确定它与范围有关(API数据已成功返回)但是我不确定如何正确地进行此操作。下面我发布了一个我想要做的骨架方法,我将非常感谢如何正确访问闭包中的this.data
。谢谢。
app.controller("Ctrl", function(//param) {
this.data = {};
this.method = function() {
var apiURL = "blablabla";
// OAuth Procedure
$angularService.getData(Client_ID, [//fields]).then(function(result) {
// do stuff
$http.get(apiURL, {
params: {
access_token: $localStorage.accessToken,
fields: "params",
format: "json"
}
}).then(function(result) {
this.data = result.data; // here it is not recognising this.data
}, function(error) {
alert("error");
console.log(error);
});
}, function(error) {
alert("error");
console.log(error);
})
}
}