$ state.go无法使用离子返回第一个视图

时间:2015-05-11 18:56:19

标签: javascript angularjs ionic

嘿大家我有问题,我可以从一个视图移动到另一个视图,但是当我找到一个并且想要回到项目的第一个视图时它根本就不会去。

我的app.js

app.config(function($stateProvider, $urlRouterProvider) {
// setup an abstract state for the tabs directive
$stateProvider

.state('game', {
    url: "/game",
    abstract: true,
    templateUrl: "templates/game.html"
})

.state('game.begin', {
    url: '/begin',
    views: {
      'begin': {
        templateUrl: 'templates/begin.html',
        controller: 'BeginCtrl'
      }
    }
})
.state('game.match', {
    url: '/match/:fileWithQuestions',
    views: {
      'match': {
        templateUrl: 'templates/match.html',
        controller: 'MatchCtrl'
      }
    }
})
.state('game.result', {
    url: '/result',
    views: {
      'result': {
        templateUrl: 'templates/result.html',
        controller: 'ResultCtrl'
      }
    }
});

$urlRouterProvider.otherwise('/game/begin');
})

我称之为问题所在页面的地方。

function countDown() {
    myTymeOut = $timeout(countDown, 1000);
    $scope.counter--;
    if($scope.counter === 0) {
        $timeout.cancel(myTymeOut);
        SendArray.sendData(answeredWords);
        releaseMidias();
        $state.go('^.result');
    }
    navigator.accelerometer.getCurrentAcceleration(onSuccess, onError);
}

问题所在的控制器:

controller.controller('ResultCtrl', function($scope, $state, $timeout, SendArray) {
screen.lockOrientation('portrait');

$scope.array = SendArray.getData();

$scope.back = function() {
    $state.go('^.begin');
}

});

调用后面函数的html

<ion-nav-view name="result">
<ion-view title="result">
    <ion-pane>
        <div class="back_div">
            <a ng-click="back()">
                <img src="img/result/voltar.png" />
            </a>
        </div>
        <div ng-repeat="item in array">
            <h1 ng-if="item.answer == true">{{item.word}}</h1>
            <h1 ng-if="item.answer == false" style="color: red;">{{item.word}}</h1>
        </div>
    </ion-pane>
</ion-view>

该功能被称为我已经尝试过警报,而state.go给了我一个对象,但它没有重定向页面......

1 个答案:

答案 0 :(得分:0)

I found out somewhere that you have to disable $ionicHistory before going back to home.

.controller('someCtrl', function($scope, $state ,$ionicHistory) {
   $scope.backFunction = function() {
     $ionicHistory.nextViewOptions({
          disableBack: true
     });
     $state.go('^.home');
   };
});

hope it helps.