2016-02-05 56 views
2

我有一个带有输入文本的表单视图。当我点击这个输入时,另一个视图被打开。不同视图上的离子返回值导航

在这个视图中,有一个输入搜索和一个列表。当我更改输入搜索中的文本时,列表发生更改。

我希望当我点击列表中的一个项目时,这个视图被关闭并且输入文本改变。但我不知道我该怎么做。

你能帮助我吗?

输入文本在我的表单视图:为什么不使用$ionicModal

'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(); 
} 
+0

请分享一下您已经开发的代码(包括JS和HTML) –

+0

tx。我编辑了我的帖子。所以我的问题是在setaddress函数中。 – user3884677

回答

1

$scope.getGeocode = function (addresssearch) { 
    ... 
    $scope.modal.show(); 
} 

<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

先前设置的模式:

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

my-modal.html点,这表明地理编码信息的模板。

+0

谢谢!这是一个很好的解决方案! – user3884677