标签云

微信群

扫码加入我们

WeChat QR Code

The controller isn't picking up the data correctly from the factory for it to display in the view (or the factory syntax isn't correct for the controller). I initially had all the data in the controller and it worked fine but when I transferred it into the factory the data would no longer display on the view. So either the controller isnt calling the factory data correctly or the factory isnt defined correctly, and I don't know which one is wrong.Contoller:app.controller('dbCtrl', ['$scope', 'myfactory', function($scope, myfactory) { myfactory.success(function(data) {$scope.test1 = results[0].data;$scope.test2 = results[1].data;$scope.test3 = results[2].data;});}]);Factory:app.factory('myfactory', ['$http', function($http, $q) { $q.all([$http.get('/url1'),$http.get('/url2'),$http.get('/url3') ]).then(function(data) { return data; })}]);


All you have to tell us now is what the actual problem is.

2019年04月22日14分44秒

alright, I've reworded my question

2019年04月22日14分44秒

thats awesome, thanks for the informative answer its helped me understand factories heaps better!

2019年04月22日14分44秒

great, so would the ctrl be:myfactory.getAll().then(function(data) { $scope.network = results[0].data; $scope.blog = results[1].data; $scope.network_all = results[2].data; });

2019年04月22日14分44秒