$ state.go和$ state.otherwise故障

时间:2016-09-08 12:10:57

标签: angularjs ionic-framework angular-ui-router

我正在尝试使用$state.go转到页面(模板)。

控制器

.controller('NavCtrl', function($scope, $location, $state) {
    $scope.openDaily = function() {
        $state.go('daily');
    };
})

它可以工作,但只有一毫秒或其他东西,因为它被重定向回到'/select'页面,因为$state.otherwise这样说。

app.js

.config(function($stateProvider, $urlRouterProvider) {
    $stateProvider
        .state('select', {
            url: '/select',
            templateUrl: 'templates/select.html',
            controller: 'selectController'
        })
        .state('daily', {
            url: '/daily',
            templateUrl: 'templates/daily.html',
            controller: 'dailyController'
        });
    $urlRouterProvider.otherwise('/select');
})

请问这是什么原因?

更新

的index.html

<body ng-app="starter" animation="slide-left-right-ios7">
    <ion-nav-view>
    </ion-nav-view>
</body>

select.html

<ion-view title="Select" ng-controller="NavCtrl">
  <ion-content>
    <div class="list-card" ng-click="openDaily()">
      <a href='#' class="item item-icon-left">
        <i class="icon ion-home"></i>
        Personal
      </a>
    </div>
  </ion-content>

      <div class="bar bar-footer bar-balanced">
        <div class="title">Add File/Folder</div>
      </div>


</ion-view>

和daily.html(模板):

<ion-view title="Select" ng-controller="NavCtrl">
</ion-view>

使用Ionic Framework。

2 个答案:

答案 0 :(得分:0)

看起来像是一个缓存问题,因为一切看起来都是正确的,请确保浏览器检查器上的文件已更改,并且控制台上的任何内容都已损坏。

P.S:如果您只想转到页面,也可以使用ui-sref="daily"

答案 1 :(得分:0)

请从href='#'标记中删除<a>。因为这会调用默认状态(这里是select状态)。

相关问题