访问特定页面时清除$ ionicHistory

时间:2016-01-27 11:32:11

标签: javascript angularjs ionic-framework

enter image description here

我在清除$ionicHistory时遇到了一些问题。

如上所述,当用户点击付款屏幕上的确定时,我想清除应用的整个观看历史记录并将用户重定向到< em>附近屏幕。

需要清除用户从付款屏幕到达的附近屏幕之前的查看历史记录。因此,用户只需在 Nearby 屏幕上看到一个菜单图标,而不是 Back 图标。

实际发生的事情付款屏幕之前的用户点击确定的视图历史记录已清除。因此,当用户登陆 Nearby 页面并按 Back (他们无法做到)时,他们最终会进入付款再次屏幕,但在付款屏幕之前无法访问任何内容。

到目前为止我的代码:

app.js

.config(function($stateProvider, $urlRouterProvider) {
  $stateProvider
    .state('app', {
    url: '/app',
    abstract: true,
    templateUrl: 'templates/menu.html',
    controller: 'AppCtrl'
  })

.state('app.payment', {
  url: '/payment/:business',
  views: {
    'menuContent': {
      templateUrl: 'templates/payment.html',
      controller: 'BookCtrl'
    }
  }
})

.state('app.service', {
  url: '/services/:service',
  views: {
    'menuContent': {
      templateUrl: 'templates/service.html',
      controller: 'ServiceCtrl'
    }
  }
});

// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/app/services');
});

controller.js

angular.module('starter.controllers', [])

.controller('BusinessCtrl', function($scope, $state, ServicesData, $stateParams, $ionicHistory) {
  $scope.business = ServicesData.getBusiness($stateParams.business);
  $scope.service = ServicesData.getBusinessServiceCategory($stateParams.business);
  $scope.clearHistory = function() {
    $ionicHistory.clearHistory();
  }
})

.controller('ServiceCtrl', function($scope, ServicesData, $stateParams) {
  $scope.service = ServicesData.getSelectedService($stateParams.service);
  $scope.businessList = ServicesData.getAllBusinessInServiceCategory($stateParams.service);
})

payment.html

<ion-footer-bar>
    <div class="button-bar" ng-controller="BusinessCtrl">
        <a class="button button-balanced" style="border-radius:0px" ui-sref="app.services" ng-click="clearHistory()">Ok</a>
        <a class="button button-stable" style="border-radius:0px" href="">View Receipt</a>
    </div>
</ion-footer-bar>

1 个答案:

答案 0 :(得分:3)

试试这个

{{1}}