我的AngularJS似乎两次运行所有内容

时间:2019-05-22 18:05:06

标签: javascript angularjs

我有这个 app.js

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
var onboardingApp = angular.module('onboardingApp', [
    'ngRoute','ngStorage'
    ]);

onboardingApp.config(function($routeProvider) {
    $routeProvider
    .when('/', {
        templateUrl: 'views/welcome.html',
        controller: 'welcomeController',
        activeTab: 'welcome'
    })
    .when('/user-info', {
        templateUrl: 'views/user-info.html',
        controller: 'userInfoController',
        activeTab: 'user-info'
    })
    .when('/service-plan', {
        templateUrl: 'views/service-plan.html',
        controller: 'servicePlanController',
        activeTab: 'service-plan'
    })

    .when('/create-account', {
        templateUrl: 'views/create-account.html',
        controller: 'createAccountController',
        activeTab: 'create-account'
    })
    .when('/access-point', {
        templateUrl: 'views/access-point.html',
        controller: 'accessPointController',
        activeTab: 'access-point'
    })
    .when('/wireless', {
        templateUrl: 'views/wireless.html',
        controller: 'wirelessController',
        activeTab: 'wireless'
    })
    .when('/done', {
        templateUrl: 'views/done.html',
        controller: 'doneController',
        activeTab: 'done'
    })
    .otherwise({ redirectTo: '/' });
})

onboardingApp.service('authInterceptor', function($q, $localStorage, $location, $timeout, $log) {
        this.responseError = (response) => {
            switch (response.status) {
                case 302:
                    let token = response.data.location.split('token=')[1];
                    $localStorage.token = token;
                    //$log.info(token);


                    //window.location.replace(response.data.location);
                    break;
            }

            return $q.reject(response);
        };
    })
onboardingApp.config(['$httpProvider', function($httpProvider) {
        $httpProvider.interceptors.push('authInterceptor');
    }])



// localStorageProvider
onboardingApp.config(['$localStorageProvider', function($localStorageProvider) {
    $localStorageProvider.setKeyPrefix('');
}])

// route
onboardingApp.run([
    '$rootScope',
    '$route',
    function($rootScope, $route) {
        $rootScope.$route = $route;

        //debugger;
    }]);

我不确定导致这种情况的原因或原因,但是我的代码似乎运行了两次。

如果我将console.log()放在我的一个控制器中的某个位置,它会console.log()翻2倍。

如何停止此操作?真烦人。

0 个答案:

没有答案