在我的 Angular 项目中,用户接受EULA,然后自动重定向到其仪表板,但是,在该重定向上,DashboardController似乎被调用了两次,在路由本身上调用了DashboardController,我检查了一下是否有误在模板中再次调用了它,但我没有。以下是我的路线和 Controller 。直接访问URL或通过EULA Controller 上的重定向访问URL都没有关系,我得到相同的结果。

路线

.config(function($httpProvider, $stateProvider, $urlRouterProvider) {

    $httpProvider.interceptors.push('httpRequestInterceptor');

    $urlRouterProvider.otherwise('/');

    $stateProvider

    .state('login', {
        url: '/',
        templateUrl: 'templates/login.html',
        data: {
            requireLogin: false
        }
    })
    .state('eula', {
        url: '/eula',
        templateUrl: 'templates/eula.html',
        data: {
            requireLogin: true
        }
    })
    .state('dashboard', {
        url: '/groups',
        templateUrl: 'templates/dashboard.html',
        data: {
            requireLogin: true
        }
    })
});

Controller :
App.controller('DashboardController', ['$scope', 'RequestService', '$state', '$rootScope', function($scope, RequestService, $state, $rootScope){

alert('test');

}]);

有任何想法吗?

按评论添加了我的HTML

index.html
<body ng-app="App">

<ion-nav-bar class="bar-positive nav-title-slide-ios7" align-title="center">
        <ion-nav-back-button class="button-icon ion-arrow-left-c"></ion-nav-back-button>
    </ion-nav-bar>
    <ion-nav-view class="slide-left-right"></ion-nav-view>
    <ui-view></ui-view>
</body>

dashboard.html
<div class="groups" ng-controller="DashboardController">
    <ion-view title="App">

        <ion-nav-buttons side="right">
            <a ui-sref="groupcreate"><span class="icon ion-ios-plus-outline"></span></a>
        </ion-nav-buttons>

        <ion-content class="padding">
            <div class="row">
                <div class="col-50"  ng-repeat="group in groups">
                    {{ group }} 1
                </div>
            </div>
        </ion-content>
    </ion-view>
</div>

最佳答案

如果您使用的是ui-router,则不必使用ng-controller。您已经在dashboard.html 中使用了它,ui-router生成了另一个-这就是为什么它被两次击中的原因。

08-19 07:06