Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ui-router annotating resolve with parameters for minifying?

ui-router breaks when minifying if the code isn't annotated properly. I have done this and most of my routes work, but this in particular does not:

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'm passing in another state into my resolve function, which should redirect to that state if some condition isn't met. I use this resolve function in several other routes, so it's a handy way of keeping the ui-router code clean.

While the non-minified version is working fine, the minified version of this doesn't work (it does nothing). But it seems like I've annotated it properly since no errors were thrown. What could be wrong?

like image 850
rublex Avatar asked Dec 19 '25 11:12

rublex


1 Answers

Please update the code with

.state('secret', {
    url: '/secret',
    controller: 'TestCtrl',
    templatesUrl: '/test.html',
    resolve: { authRedirect: ['authRedirect', function(authRedirect){ return authRedirect('other')}] }
})
like image 106
Nikhil Aggarwal Avatar answered Dec 21 '25 01:12

Nikhil Aggarwal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!