自动填充文本框不会触发选定的值
我的AngularJs应用程序中的自动完成文本框出现问题.当我按任意键进行自动完成建议时,我的建议将显示在文本框中,而选定的值将显示在文本框中.当我尝试通过html页面上的 ng-model
显示值时,它仅显示我键入以获得自动完成建议的字符,而不显示建议值.
I have an issue with my autocomplete textbox in my AngularJs app. When I press any key for autocomplete suggestion, my suggestion is shown in the textbox and the selected value is shown inside the textbox. When I try to show the value by its ng-model
on the html page, it only shows the character I typed to get the autocomplete suggestion and not the suggested value.
谢谢!
这是我的HTML代码:
Here is my HTML code:
<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
});
}
而不是使用 $ scope
来检索文本框的值,而应使用 document.getElementById("id").value 代码>
Instead of using $scope
to retrieve textbox's value, use document.getElementById("id").value
var pickup_location = document.getElementById("pickup_location").value;
希望这会有所帮助!