Ui-router annotating solution with parameters to minify?

ui-router breaks on minification if the code has not been annotated correctly. I did this and most of my routes work, but in particular they don't:

var authRedirect = function(s) {
    return ['$state', '$q', 'AuthService', function($state, $q, AuthService) {
        var d = $q.defer();
        var is_auth = AuthService.checkAuth();
        if(!is_auth) {
            d.reject();
            $state.go(s);
        } else 
           d.resolve();
        return d.promise;
    }];
}

// ...

.state('secret', {
    url: '/secret',
    controller: 'TestCtrl',
    templatesUrl: '/test.html',
    resolve: { authRedirect: authRedirect('other') }
})
.state('other', { .... } )

      

I am passing another state to my function resolve

, which should redirect to that state if some condition is not met. I use this resolution feature in several other routes, so it's a convenient way to keep the ui-router code clean.

While the non-thumbnail version works fine, the mini version doesn't work (it doesn't do anything). But it seems to me that I annotated it correctly because there were no errors. What could be wrong?

+3


source to share


2 answers


You can also try to update code like this



.state('secret', {
    url: '/secret',
    controller: 'TestCtrl',
    templatesUrl: '/test.html',
    resolve: { authRedirect: function() { return authRedirect('other')} }
})

      

0


source


Please update your code with



.state('secret', {
    url: '/secret',
    controller: 'TestCtrl',
    templatesUrl: '/test.html',
    resolve: { authRedirect: ['authRedirect', function(authRedirect){ return authRedirect('other')}] }
})

      

+1


source







All Articles