我正在使用 PHP 将数据获取到我的工厂,这在控制器内的成功回调函数中正确显示。但是,即使在将返回的数据分配给 $scope.customers 之后,如果我在回调之后执行 console.log($scope.customers),它也不存在,并且我的视图的 [ng-repeat] 也没有拾取它。
如果我将返回的数据分配给我的 $scope 对象,知道为什么我的数据范围会被限制在成功回调内吗?
var customersController = function($scope, customersFactory) {
$scope.customers = [];
customersFactory.getAllData()
.success(function(customers) {
$scope.customers = customers;
console.log($scope.customers); // Object with correct data
}); // No errors so only showing happy path
console.log($scope.customers); // empty []
};
customersModule.controller('customersController', ['$scope', 'customersFactory', customersController]);