<!doctype html>
<html ng-app="ui.bootstrap.demo">
  <head>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular-animate.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.6.1/angular-sanitize.js"></script>
    <script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-2.5.0.js"></script>
    <script src="example.js"></script>
    <link href="//netdna.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
  </head>
  <body>




<div class='container-fluid typeahead-demo' ng-controller="TypeaheadCtrl">


<select ng-model="dataa" ng-options="opt as opt.label for opt in units" ></select>

<br><br><br>


    <pre>Model: {{asyncSelected1 | json}}</pre>
    <input type="text" ng-model="asyncSelected1" placeholder="first" uib-typeahead="address for address in first($viewValue)" typeahead-loading="loadingLocations" typeahead-no-results="noResults" class="form-control">
    <i ng-show="loadingLocations" class="glyphicon glyphicon-refresh"></i>
    <div ng-show="noResults">
      <i class="glyphicon glyphicon-remove"></i> No Results Found
    </div>


</div>
  </body>
</html>
angular.module('ui.bootstrap.demo', ['ngAnimate', 'ngSanitize', 'ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('TypeaheadCtrl', function($scope, $http) {

  
  
   $scope.units = [
         {'id': 1, 'label': 'one'},
         {'id': 2, 'label': 'two'}
      ];

   $scope.data= $scope.units[0];
  
  
  $scope.selected = undefined;
  
  $scope.first = function(val) {
    console.log($scope.dataa);
    if($scope.dataa.id == 1)
    {    
      console.log("first");
      return $http.get('//maps.googleapis.com/maps/api/geocode/json', {
      params: {
        bounds: val,
        sensor: false
      }
    }).then(function(response){
      return response.data.results.map(function(item){
        return item.formatted_address;
      });
    });
    }
    else
    {
     return $http.get('//maps.googleapis.com/maps/api/geocode/json', {
      params: {
        address: val,
        sensor: false
      }
    }).then(function(response){
      return response.data.results.map(function(item){
        return item.formatted_address;
      });
    });
    }
  };
  


});