javascript - Controller being called twice in Ionic (AngularJS) -
in angular project user accepts eula automatically redirected dashboard, however, on redirect dashboardcontroller seems being called twice, dashboardcontroller being called on route itself, have checked see if have accidently called again in template havn't. below route & controller. doesn't appear matter if access url directly or via redirect on eula controller, same result.
the routes
.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 } }) });
the controller:
app.controller('dashboardcontroller', ['$scope', 'requestservice', '$state', '$rootscope', function($scope, requestservice, $state, $rootscope){ alert('test'); }]);
any ideas?
added html per comments
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>
if using ui-router
don't have use ng-controller
. have used in dashboard.html, generated ui-router
- that's why hit twice.
Comments
Post a Comment