Thiago Ramires
Thiago Ramires

Reputation: 55

$state.go not working to go back for the first view with ionic

hey everybody i have a problem, I can move normaly from one view to another, but when i get to one and want to go back to the first view of the project it simply don't go.

my 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');
})

the place I call the page that the problem is.

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);
}

the controller where the problem is:

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

$scope.array = SendArray.getData();

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

});

the html where the back funciton is called

<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>

the function is called i've already tried with alerts, and the state.go gives me an object, but it doesn't redirect the page...

Upvotes: 0

Views: 659

Answers (1)

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.

Upvotes: 0

Related Questions