Angular -UI Allow Promise Object Inside $ urlRouterProvider.when ()

I try to configure some basic application data inside an object module.config(), and I only do this when the user clicks on the application with a unique key attached to a specific entry point, otherwise my states will be resolved with different answers.

I use $urlRouterProvider.when()to catch the user at the specified entry point, then resolve the promise ( $http.get()), and then return the state. But it doesn't seem to help. The data itself is returned, but the function does not return the path, and I cannot understand why.

$urlRouterProvider.when('/hi/:userkey',function($match,$rootScope, $http){
        $http.get('http://api.com/login/'+$match.userkey)
            .success(function(result){
                $rootScope.data = result;
                  return '/home';
            })

        });

I also tried setting the return value inside .then():

.then(function(){
    return '/home';
})

I get no errors, but the return value is not processed.

+3
2

, , , , , , , . , , esalija , , , ui.router. , , , , .

$urlRouterProvider.when('/hi/:userkey',function($match, $http, Api, $state){
        return $http.get('http://api.site.com/index.php/login/'+ $match.userkey).success(function(result){

            Api.userkey = $match.userkey;
            Api.appdata = result;

        }).then(function(){
            $state.go('app');
        });

devsite/#/hi/5300e0ce9dfb8

, , , , :

$urlRouterProvider.when(state.url, ['$match', '$stateParams', function ($match, $stateParams) {
    if ($state.$current.navigable != state || !equalForKeys($match, $stateParams)) {
        $state.transitionTo(state, $match, false);
    }
}]);
+2

$urlRouterProvider.when('/hi/:userkey', function ($match, $rootScope, $http) {
    return $http.get('http://api.com/login/' + $match.userkey)
        .then(function (result) {
            $rootScope.data = result;
            return '/home';
        });
});
+1
source

All Articles