我正在使用 http get 函数从服务获取 json 数组。如何设置对 Controller locations 元素的响应。
function MainCtrl($http,myService) {
this.locations = null;
myService.async().then(function(d) {
? = d;
});
}
响应 d 格式良好 (JSON)
最佳答案
您只需获取对当前上下文的引用,然后在回调中使用该变量引用
function MainCtrl($http,myService) {
var vm = this;
vm.locations = []; // initialise properly
myService.async().then(function(d) {
vm.locations = d;
});
}
关于javascript - 如何使用http get返回值设置 Angular Controller 元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30912027/