2015-06-25 36 views
2

我在自動填充文本框中使用角度js應用時出現問題。當我按任意鍵進行自動填充建議時,我的建議將進入文本框,選定的值將進入文本框。當我嘗試在html頁面上通過它的ng-model顯示值時,它顯示我首次輸入自動完成建議的字符,而不是建議的值。自動填充文本框未觸發選定的值

謝謝!!!

這裏是我的HTML代碼: -

<input type="text" id="tags" data-ng-model="placeselected" data-ng-keyup="complete()"/> 
<br />{{placeselected}} 

這裏是我的JS: -

$scope.complete = function() { 
    $scope.availablePlaces = []; 
    $http({ 
     method : 'GET', 
     url : 'http://localhost:8080/orion-orbit/newclue/cities/ '+ $scope.cityselect.cityCode + '/clueAnswers' 
    }).success(function(data, status, headers,config) { 
     $scope.getPlaces=data; 
    }).error(function(data, status, headers,config) { 
     // called asynchronously if an error occurs 
     // or server returns response with an error status. 
    }); 
    angular .forEach($scope.getPlaces,function(value) { 
     if (value.getPlaces !=' ') { 
      $scope.availablePlaces.push(value.ans); 
     } 
    }); 


    $("#tags").autocomplete({ 
     source : $scope.availablePlaces 
    }); 
} 
+0

有沒有想到這一點? – WMios

回答

1

而不是使用$scope檢索文本框的值,使用document.getElementById("id").value

var pickup_location = document.getElementById("pickup_location").value; 

希望這有助於!

+0

適合我 – sajalsuraj