У меня есть 2 метода app.run. Как остановить первый метод, пока обещание не будет разрешено?
angular.module('app', [
... ])
.constant('AppConstants', constants)
.config(appConfig)
.run((UserService, User) => {
'ngInject';
console.log('apprun')
UserService.acl()
.then((data) => {
console.log('data')
User.setACL(data)
console.log(data)//finsish this first then go to second run call
})
.catch((err) => {
console.log(err);
})
})
.run(appRun)
.component('app', AppComponent)
Мне нужно завершить
Usercervice.acl
вызовите сначала, а затем выполните второй метод run(apprun), необходимо вызвать здесь код изUserService.acl()
let acl = () => {return $ http.get (AppConstants.api +
/acl/user-resources
).then ((res) => {return res.data})
}
1 ответ
Решение
.constant('AppConstants', constants)
.config(appConfig)
.run((UserService, User) => {
'ngInject';
console.log('apprun')
UserService.acl()
.then((data) => {
console.log('data')
User.setACL(data)
console.log("done with first run")//finsish this first then go to second run call
/*here is my second run block i.e. on success of first one*/
var acl = () => {
return $http .get(AppConstants.api + /acl/user-resources).then((res) {
return res.data
})
}
})
.catch((err) => {
console.log(err);
})
})
.run(appRun)
.component('app', AppComponent)