$q
synchronize async dependencies
Problem
Initialize i18n strings for multiple dependencies.
SystemSrv gets i18n strings from server and sets the page title after getting response
OrderCtrl should not be initialized before strings are loaded.
Sync to seam/resource/api/system is needed in two or more places.
Solution
$q promises
SystemSrv.deferred = $q.defer()
SystemSrv.deferred.promise = SystemSrv.deferred.promise.then ->
init code
pass in SystemSrv where sync is needed.
Questions?
Example
deferredFirstService = $q.defer()
deferredFirstService.promise.then ->
$scope.OrderCtrl.init()
SystemSrv.deferredSystem.promise = SystemSrv.deferredSystem.promise.then( ->
$scope.OrderCtrl.catalog = $scope.OrderCtrl.catalog.get({offeringId: sscUtils.getQueryParam('id')},
() ->
deferredFirstService.resolve()
,
(error) ->
window.location = 'home.seam'
)
)$q
By samuli
$q
- 1,053