angularjsangularjs-scopeangular-ui-routerangular-ui-router-extras

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


Solution

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