가 나는 등과 같은 공장 things
에 추가) getThings()
이 빈 배열을 반환해야하므로 $http.post()
호출이 해결되기 전에 반환해야합니까?비동기 각도 약속 및 변수 초기화
더 나은 대안인가요?
app.controller('myController', function($scope, thingFactory) {
$scope.things = []
thingFactory.initializeThings
.then(function(response) {
$scope.things = response.data;
}, function (response) {
// some error handling code here...
});
}
컨트롤러가 약속을 생각하지 않고 안전하게 가져올 수있는 안전한 대안이 있습니까?
'getThings'가 약속을 반환하지 않는 이유는 무엇입니까? – Bergi