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]);