我想将查询[我正在文本框中输入的内容]发送为url作为参数, 我无法通过
脚本代码
var myApp = angular.module('myApp', ['angucomplete-alt']);
myApp.controller('ngautocomplete', ['$scope', '$http', function ($scope, $http) {
$scope.Places = [];
$scope.SelectedPlace = null;
$scope.afterSelectedPlace = function (selected) {
if (selected) {
$scope.SelectedPlace = selected.originalObject;
}
}
$http({
method: 'GET',
url: '../HttpHandler/AutoCompleteMapMyindiaAddress.ashx',
params: {
query: ,
current_lat: ,
current_lng:
}
}).then(function (response) {
console.log(response.data)
$scope.Places = response.data.data.suggestedLocations.placeAddress;
},
function (error) {
console.log(error)
}
)
}])
HTML代码
<div data-ng-app="myApp" data-ng-controller="ngautocomplete">
<div angucomplete-alt id="txtLocation" placeholder="Enter the location" pause="100"
selected-object="afterSelectedPlace" local-data="Places" search-fields="PlaceName"
text-field="CountryName" minlength="1" input-class="form-control" match-class="highlight"s>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angucomplete-alt/2.5.0/angucomplete-alt.min.js"></script>
</script>
我不知道如何发送查询以及如何绑定到texbox。
答案 0 :(得分:0)
在末尾附加查询参数:
url: '../HttpHandler/AutoCompleteMapMyindiaAddress.ashx?someQuery='+<variableName>
答案 1 :(得分:0)
最后我找到了这个问题的解决方案
angularjs代码
app.directive('autoComplete', ['$filter', '$http', function ($filter, $http) {
return {
restrict: 'A',
link: function ($scope, elem, attrs) {
elem.autocomplete({
source: function (request, response) {
//request watever we enter in location textbox
var params = request.term;
console.log(params + ' |' + map.getCenter().lat + ' ' + map.getCenter().lng);
$http.get('../HttpHandler/AutoCompleteMapMyindiaAddress.ashx', {
params: {
query: params,
current_lat: map.getCenter().lat,
current_lng: map.getCenter().lng
}
}
).then(function (d) {
$scope.suggestedloc = d.data.data.suggestedLocations;
var data = $scope.suggestedloc;
if (data) {
var result = $filter('filter')(data, { placeName: params });
console.log(result)
angular.forEach(result, function (item) {
item['value'] = item['placeName'] + ' ' + item['placeAddress'];
});
}
response(result);
}, function (error) {
console.log(error);
});
},
minLength: 3,
select: function (event, ui) {
event.preventDefault();
console.log(ui);
console.log('ui')
$scope.$apply(function () {
$scope.GetLatLon(ui.item);
});
},
})
}
};
}]);
和html
<input auto-complete class=" form-control" data-ng-model="Location" placeholder="Search Location" style="width: 280px; text-align: center" type="text" />
我提供的脚本代码是
<script src="../Content/js/vendor/jquery-1.11.1.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="../Content/js/jquery-ui.js"></script>
每隔3个字母,我就会击中服务器,并且会收到邮件