AngularJS change URL in module.config

angular-routing, angularjs, restangular

Solution

the correct way for handling this problem is configuring restangular in `run` method of angularjs

app.run(Restangular , $location){
    Restangular.setErrorInterceptor(function (resp) {
        $location.path('/login');
        return false;
    });
}

Problem

I use `Restangular` in my angularjs App & use `setErrorInterceptor` to handle response error in one place. I want to redirect user to login page if an error occured. I know that the only `providers` & `constants` are injectable in configuration phase. ``` var app = angular.module('ourstandApp', ['ngRoute', 'restangular', 'ui.bootstrap', 'ngCookies', 'angularFileUpload']); // Global configuration app.config(function (RestangularProvider, baseRequestConfig, $routeProvider, urlsProvider) { var getBaseRequestUrl = function () { return baseRequestConfig.protocol + "://" + baseRequestConfig.hostName + ":" + baseRequestConfig.portNumber + baseRequestConfig.resourcePath; } var initializeRoute = function () { $routeProvider.when('/', { controller: LoginController, templateUrl: 'views/login.html' }). otherwise({ redirectTo: '/' }); } initializeRoute(); RestangularProvider.setBaseUrl(getBaseRequestUrl()); RestangularProvider.setErrorInterceptor(function (resp) { goToLogin(); // i want to change url to login page return false; }); }); ```

Original source

Related problems