简体   繁体   中英

I have 2 app.run method.how to halt in first method until promise is resolved?

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)
  1. I need to complete Usercervice.acl call first and then run second run(apprun) method need to be called here is code from UserService.acl()

    let acl = () => { return $http.get(AppConstants.api + /acl/user-resources ) .then((res) => { return res.data })
    }

.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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM