$q 의 all 함수를 이용.
$q.all([promise1, promise2,,]).then(function(datalist){
datalist[0] ; promise1,
}, function(errorlist){
});
promise1 = $resource(,,,,).$promise 로 사용해서
resolve - {Object.<string, function>=} - An optional map of dependencies which should be injected into the controller. If any of these dependencies are promises, the router will wait for them all to be resolved or one to be rejected before the controller is instantiated. If all the promises are resolved successfully, the values of the resolved promises are injected and $routeChangeSuccess event is fired. If any of the promises are rejected the $routeChangeError event is fired. For easier access to the resolved dependencies from the template, the resolve map will be available on the scope of the route, under$resolve (by default) or a custom name specified by the resolveAs property (see below). This can be particularly useful, when working with components as route templates. function service(name, constructor) {
return factory(name, ['$injector', function($injector) {
return $injector.instantiate(constructor);
}]);
}
$injector.instaniate()에 생성자를 넣어 반환하는데 이 함수에서 Object.create()로 해당 생성자를 인스턴스화 한다. 이렇게 얻은 인스턴스를 factory에 넣어 나머지는 factory와 동일하게 처리하는 것을 확인할 수 있다. 그래서 라이브러리의 실제 의도와는 다른 구현도 문제 없이 구동될 수 있는 것이다..service()메소드와 .factory() 메소드의 차이는 객체를 생성하는 방법에서 차이가 있다.function SomeService () {
this.someMethod = function () {
// ...
};
}
angular
.module('app')
.service('SomeService', SomeService);
function AnotherService () {
var AnotherService = {};
AnotherService.someValue = '';
AnotherService.someMethod = function () {
// ...
};
return AnotherService;
}
angular
.module('app')
.factory('AnotherService', AnotherService);
$http가 대표적이며 많은 기능이 프로바이더로 구현되어 있다.