Chr*_*ton 4 javascript angularjs angularjs-routing angularjs-controller ionic-framework
在我的角度项目中,用户接受EULA,然后自动重定向到他们的仪表板,但是,在此重定向上,DashboardController似乎被调用了两次,DashboardController正在路由本身被调用,我已经检查过我是否有意外在模板中再次调用它,但我没有.以下是我的路线和控制器.如果我直接或通过EULA控制器上的重定向访问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
}
})
});
Run Code Online (Sandbox Code Playgroud)
控制器:
App.controller('DashboardController', ['$scope', 'RequestService', '$state', '$rootScope', function($scope, RequestService, $state, $rootScope){
alert('test');
}]);
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
根据评论添加我的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>
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
如果您正在使用ui-router,则不必使用ng-controller.您已经在dashboard.html中使用了它,另一个是由ui-router它生成的- 这就是它被击中两次的原因.
好了,所以很长一段时间的调试和检查的东西出来后,我发现,这是与导航栏离子的问题,从本质上讲,我打电话<ui-view></ui-view>与<ion-nav-view></ion-nav-view>在同一页上,所以对我的看法这又基本上增加了一倍调用控制器两次.
| 归档时间: |
|
| 查看次数: |
6031 次 |
| 最近记录: |