私は、バックエンドに検索のために渡される照会パラメーターを使用するプロジェクトを持っています。AngularJSフォームで照会パラメーターが空であるかどうかを確認する方法
AngularJSの$ http.getメソッドを使用して渡されます。
一部のパラメータは検索に必須ではないため、空の場合はURLに入れないようにしてください。
どうすればこの機能を利用できますか?以下は
私のコードです:
<!DOCTYPE html>
<html lang="en" ng-app = "searchApp">
<script type="text/javascript">
var searchApp = angular.module("searchApp", []);
searchApp.controller("searchListingsCtrl", ['$scope', '$http', function($scope, $http) {
$scope.searchListings = function(){
if ($scope.checkIn == '') {}
var searchListingObj = {
checkIn : $scope.checkIn,
checkOut : $scope.checkOut,
country : $scope.country,
city : $scope.city,
state : $scope.state,
accommodates : $scope.accommodates,
}
var res = $http.get('http://www.localhost:8080/messenger/webapi/listings', searchListingObj);
res.success(function(data, status, headers, config) {
$scope.message = data;
});
res.error(function(data, status, headers, config) {
alert("failure message: " + JSON.stringify({data: data}));
});
};
}]);
</script>
<body ng-controller="searchListingsCtrl">
<form action="/listings" name="listings" ng-submit="searchListings()">
<input type="text" name="neighborhood" placeholder="Neighborhood:" ng-model="state">
<input type="text" name="town" placeholder="Town:" ng-model="city">
<input type="text" name="country" placeholder="Country:" ng-model="country">
People:<select class="peopleSelect" placeholder="People:" ng-model="accommodates"> </select>
<input type="text" id="arrival" name="arrival" value="Arrival" ng-model="checkIn">
<input type="text" id="departure" name="depart" value="Departure" ng-model="checkOut">
<input type="submit" name="submit" value="Search" id="Search_submit">
</form>
</body>
あなたの質問を理解できません。あなたはそれを詳しく教えてもらえますか? –
私はそれを改め、もう一度質問をチェックしてください。 –
あなたのコードはどのようになっていますか? –