不同视图上的离子返回值导航

时间:2016-02-05 07:48:01

标签: ionic-framework

我有一个带有输入文本的表单视图。单击此输入时,将打开另一个视图。

在此视图中,有一个输入搜索和一个列表。当我从输入搜索中更改文本时,列表会更改。

我想在单击列表中的一个项目时,此视图将关闭,输入文本将更改。但我不知道如何做到这一点。

你能帮我吗?

表格视图中的输入文字:

<div class="select-typeevent">
    <ion-item nav-clear menu-close ui-sref="menu.setlocation">
        <label class="padding">
            Address:
        </label>
    </ion-item>
</div>

我的搜索视图:

<ion-view view-title="Address" class="content">
    <ion-content>
        <h1>Address</h1>
        <div class="bar bar-header item-input-inset">
            <label class="item-input-wrapper">
                <i class="icon ion-ios-search placeholder-icon"></i>
                <input class="border-none" name="txtssearch" type="search" placeholder="Search" ng-model="addresssearch" ng-change="getGeocode(addresssearch)">
            </label>
            <button class="button button-clear" ng-click="addresssearch='';getGeocode(addresssearch)">
                Annuler
            </button>
        </div>
       <div class="list" >
            <a ng-repeat="addr in addresslist" class="item"  ng-click="setaddress(addr)">
                {{addr.address}} {{addr.location}}
            </a>
        </div>
    </ion-content>
</ion-view>

和js:

    'Use Strict';
angular.module('App').controller('setlocationController', function ($scope,$state, $cordovaOauth, $localStorage, $location, $http, $ionicPopup,$firebaseObject,$ionicHistory, Auth, FURL, Utils) {


    $scope.getGeocode = function (addresssearch) {

        $scope.geodata = {};
        $scope.queryResults = {};
        $scope.queryError = {};

        $http.get('https://maps.googleapis.com/maps/api/geocode/json?address=' + addresssearch)
          .then(function (_results) {
              $scope.addresslist = [];
              $scope.queryResults = _results.data.results;
              console.log($scope.queryResults);
              $scope.queryResults.forEach(function(result) {
                  $scope.addresslist.push({ 'address': result.formatted_address, 'location': result.geometry.location });
              });

          }, 
           function error(_error){
               $scope.queryError = _error;
           })
    };

    // Here I want when I click one item of the list, this view gets closed and the input text of formview change.
    $scope.setaddress = function (addr) {
    $scope.setaddress = addr;
    $ionicHistory.backView();
}

1 个答案:

答案 0 :(得分:1)

为什么不使用$ionicModal

$ionicModal.fromTemplateUrl('my-modal.html', {
    scope: $scope,
    animation: 'slide-in-up'
  }).then(function(modal) {
    $scope.modal = modal;
  });

以前设置模态:

my-modal.html

.authenticate().then().catch(function(error){...});指向显示地理编码信息的模板。