这是我的服务:
'use strict';
app
.service('myService', function($http) {
this.getJSON = function() {
return $http.get('someUrl/dataForm').then(function(data){
return data.result;
});
};
});
在我的 Controller 中我有:
'use strict'
app.controller('myController', function ($scope, myService) {
myService.getJSON().then(function(data){
$scope.myData =data;
});
console.log($scope.myData);
});
我可以看到 http 调用成功返回 JSON 值,但控制台日志显示 myData 的值未定义。 我做错了什么?
最佳答案
将console.log放入其中
myService.getJSON().then(function(data){
$scope.myData =data;
console.log($scope.myData);
});
关于javascript - 服务将未定义返回给 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39755707/