2015-07-31 11 views
5

Ich habe eine Zurück-Taste, die, wenn ich die ng-click='goBack()' treffe. Ich kann die URL im Browser sehen, der von http://app:8888/#/main/payments zu http://app:8888/#/main/products/7 wechselt, der der richtige Pfad ist, zu dem ich zurückgehen möchte, aber das Problem ist, dass die Ansicht dort nicht übergeht.Ionic, wie man programmgesteuert zurück geht

Ich muss auf Refresh-Taste drücken, um dorthin zu gehen oder ein window.location.reload nach dem $ionicHistory.goBack(); zu tun.

Ich möchte nicht die gesamte Seite neu laden Ich möchte diese Ansicht auf die vorherige umstellen.

das ist mein html

 <div class="row"> 
     <div class="col col-25"> 
      <button ng-click="goBack()" class="button button-large button-block button-royal">Go Back</button> 
     </div> 
    </div> 

dies mein Controller ich weiß nicht, ob dies helfen würde,

.controller('paymentsController', function($scope, $localStorage, $log, $state, $window, $ionicHistory){ 

$scope.goBack = function(){ 

    $ionicHistory.goBack(); 

} 


}) 

das ist mein app.js ist.

$state.transitionTo('main'); 

hier 'main' ist Ihrer Ansicht nach Namen, den Sie in Ihre urlrouterprovider definiert haben:

// Ionic Starter App 

// angular.module is a global place for creating, registering and retrieving Angular modules 
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html) 
// the 2nd parameter is an array of 'requires' 
angular.module('starter', ['ionic', 'starter.controllers', 'starter.services', 'ngStorage']) 

.run(function($ionicPlatform) { 
    $ionicPlatform.ready(function() { 
     // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard 
     // for form inputs) 
     if(window.cordova && window.cordova.plugins.Keyboard) { 
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); 
     } 
     if(window.StatusBar) { 
      StatusBar.styleDefault(); 
     } 
    }); 
}) 

.config(function($stateProvider, $urlRouterProvider){ 

    //$ionicConfigProvider.views.transition('none'); 

    $urlRouterProvider.otherwise('/'); 

    $stateProvider 

     .state('login',{ 
      url: '/', 
      templateUrl: 'templates/login.html', 
      controller: 'loginController' 
     }) 

     .state('main', { 
      url: '/main', 
      templateUrl: 'templates/main.html', 
      controller: 'mainController', 
      abstract: true 
     }) 

     .state('main.categories', { 
      url: '/categories', 
      views: { 
       'categories': { 
        templateUrl: 'templates/categories.html', 
        controller: 'categoriesController' 
       } 
      } 
     }) 

     .state('main.products', { 
      url: '/products/:productId', 
      views: { 
       'products': { 
        templateUrl: 'templates/products.html', 
        controller: 'productsController' 
       } 
      } 
     }) 

     .state('main.payments', { 
      url: '/payments', 
      views: { 
       'payments': { 
        templateUrl: 'templates/payments.html', 
        controller: 'paymentsController' 
       } 
      } 
     }) 

}) 
+1

möglich Duplikat [wie eine Zurück-Schaltfläche in der Fußzeile (ionische Framework) zu schaffen?] (Http://stackoverflow.com/questions/22739459/how-to-create-a-back-button-im-fuß-ionen-framework) – callmekatootie

Antwort

0

Verwenden $ Staat bestimmte Ansicht zu umleiten.

ODER

Sie auch $ Lage

$location.path('main'); 

vergessen Sie nicht, $ Zustand oder $ Standort in Ihrer Steuerung Parameter verwenden können, um hinzuzufügen.

2

Rufen Sie diese von Ihrem Controller, wo Sie zurück gehen wollen ..

var backCount = 1; 
$rootScope.$ionicGoBack(); 
$rootScope.$ionicGoBack = function(backCount) { 
    $ionicHistory.goBack(backCount); 
}; 
Verwandte Themen