2016-04-09 13 views
0

で元に戻るように私はこの使用して、イオン/コルドバを達成しようとしています:- どのようにリストに移動して選択し、選択した値

ボタンを押し上

新しい画面に行きますリスト

とリスト

の項目を選択し、選択された値と元に戻ります。

誰かがこれを達成する方法を説明し、これがどのように達成されたかの例を挙げることができますか?ありがとう。

+0

ほとんどこの中で解決するが、まだいくつかの問題を持っているhttp://stackoverflow.com/questions/36523712/ionic-how-to-detect-and-pass-value -back-to-original-view-ionichistory-go – Axil

答えて

0

あなたが既に試したことを提供してください。しかし、私はあなたが望むものを理解しています:

すべてのページ/テンプレートが正しくapp.js内に設定され、controller.jsとservices.jsが設定されていることを確認してください。

コントローラ間のデータ受け渡しはサービスを介して行われます。set()およびget()メソッドを使用して、サービスを各ページのコントローラに挿入し、それに応じて値を変更して受信することができます。

HTML(最初のページ):

<ion-view view-title="firstPage"> 
    <ion-content> 
     <!-- Binds selected value to div --> 
     <div ng-bind="selected.selec"> </div> 
     <!-- Goes to next page --> 
     <button class="button" ng-click="next()"> 
      Next 
     </button> 
    </ion-content> 
</ion-view> 

コントローラ(ファースト):

.controller('firstPageCtrl', function($scope, $state, savedList) { 
    // Go to next page 
    $scope.next = function() { $state.go("secPage"); } 

    // Get selected value from service, savedList 
    $scope.selected = { selec: "" }; 
    $scope.selected.selec = savedList.get(); 
}) 

HTML(第二ページ):

<ion-view view-title="secPage"> 
    <ion-content> 
     <!-- Radio buttons will only allow one value to be selected at one time --> 
     <ion-list> 
      <!-- Pass in value of radio button to update function --> 
      <ion-radio ng-model="choice" ng-value="'A'" ng-change="update('A')">Choose A</ion-radio> 
      <ion-radio ng-model="choice" ng-value="'B'" ng-change="update('B')">Choose B</ion-radio> 
     </ion-list> 
     <!-- Goes back to first page --> 
     <button class="button" ng-click="back()"> 
      Go Back 
     </button> 
    </ion-content> 
</ion-view> 

コントローラ(二):

.controller('secPageCtrl', function($scope, $state, savedList) { 
    $scope.back = function() { $state.go("firstPage"); } 

    // Send selected value to service, savedList 
    $scope.update = function(selec) { 
     savedList.set(selec); 
    } 
}) 

サービス:

.factory('savedList', function() { 
    var selec = ""; 

    // Sets selec to what ever is passed in 
    function set(data) { 
     selec = data; 
    } 
    // Returns selec 
    function get() { 
     return selec; 
    } 

    return { 
     set: set, 
     get: get 
    } 
}) 

https://docs.angularjs.org/guide/services

関連する問題