2016-03-28 14 views
0

1ページのアプリケーションで作業しています。可能であれば、前のページに戻るために非常に簡単なコードを探していますスワイプ。私は多くを見てきましたが、すべてが非常に複雑で非常に異なっているようです。右と左にスワイプして角を使ってページ上を4番目に移動する簡単なコード

私がしたいのは、スワイプでページから4番目に戻ることです。本当に複雑すぎるものはありません。おそらくng-swipe-rightng-swipe-leftを使用していますか?また、これはガーデンセンターのアプリで、在庫の一部を検索することができます。ここで

私のindex.htmlコードです:

var app = angular.module('myApp',[ 
    'ngRoute', 
    'myApp.Home', 
    'myApp.Search', 
    'myApp.Inventory', 
    'myApp.Sub', 
    'myApp.Details' 
]); 

app.config(function($routeProvider){ 
    $routeProvider. 
     when('/home', { 
      templateUrl: 'templates/home/home.html', 
      controller: 'HomeController' 
     }). 
     when('/search', { 
      templateUrl: 'templates/search/search.html', 
      controller: 'SearchController' 
     }). 
     when('/inventory', { 
      templateUrl: 'templates/inventory/inventory.html', 
      controller: 'InventoryController' 
     }). 
     when('/coupons', { 
      templateUrl: 'templates/coupons/coupons.html' 
     }). 
     when('/sales', { 
      templateUrl: 'templates/sales/sales.html' 
     }). 
     when('/events', { 
      templateUrl: 'templates/events/events.html' 
     }). 
     when('/locations', { 
      templateUrl: 'templates/locations/locations.html' 
     }). 
     when('/subInventory/', { 
      templateUrl: 'templates/subInventory/subInventory.html', 
      controller: 'SubInventoryController' 
     }). 
     when('/detailsInventory/:productId', { 
      templateUrl: 'templates/detailsInventory/detailsInventory.html', 
      controller: 'DetailsInventoryController' 
     }). 
     otherwise({ 
      redirectTo: '/home' 
    }); 
}); 

答えて

0

使用ngSwipeLeft /右

angualrディレクティブng-swipe-left="expression"

を使用します。ここでは

<div class="main"> 
    <div ng-view></div> 
</div> 

は私のapp.jsコードがあります式の

では、スコープにバインドされた関数を呼び出すことができます。この関数は、状態関数goを使用することができます。

$scope.goLeft = function(){state.go('someState')} 

あなたは、アプリ内のどこに行きたいかを定義するために、いくつかのパラメータを調べる必要があります。または、すべての状態でこの機能を持ち、左右の状態をハードコードすることができます。

+0

'function goBack(){ window.history.back(); } ' これはng-swipe-rightでうまくいくと思いますか? –

+0

これは決して使用されていませんが、正しい履歴がない状態になることができれば混乱する可能性があります –

関連する問題