Javascript 如何从自动完成位置文本字段捕获angularjs范围内的数据
我正在开发一个angularjs表单,其中包含位置文本字段。对于位置文本字段,我使用谷歌地图自动完成。问题是,我无法使用DataNG模型存储完整的数据数据库。因为,只有输入的文本被绑定并存储在数据库中,而不是完整的数据。例如,如果我键入“Pun”,autocomplete将填充“Pun,Maharashtra,India”,但只有“Pun”存储在数据库中(因为我只在文本字段中键入了“Pun”。如何捕获完整数据并将其转换为json并存储在数据库中?请帮助我。提前感谢 这是我的密码: JavaScriptJavascript 如何从自动完成位置文本字段捕获angularjs范围内的数据,javascript,angularjs,json,spring,rest,Javascript,Angularjs,Json,Spring,Rest,我正在开发一个angularjs表单,其中包含位置文本字段。对于位置文本字段,我使用谷歌地图自动完成。问题是,我无法使用DataNG模型存储完整的数据数据库。因为,只有输入的文本被绑定并存储在数据库中,而不是完整的数据。例如,如果我键入“Pun”,autocomplete将填充“Pun,Maharashtra,India”,但只有“Pun”存储在数据库中(因为我只在文本字段中键入了“Pun”。如何捕获完整数据并将其转换为json并存储在数据库中?请帮助我。提前感谢 这是我的密码: JavaScr
<script type="text/javascript">
var app = angular.module('formSubmit', []);
app.controller('FormSubmitController',[ '$scope', '$http', function($scope, $http) {
/* $scope.myDataBlurred = $scope.area; */
$scope.list = [];
$scope.headerText = 'AngularJS Post Form Spring MVC example: Submit below form';
$scope.blurred = function() {
$scope.myDataBlurred = $scope.area;
}
$scope.submit = function() {
var formData = {
"agreement_exp_date" : $scope.agreement_exp_date,
"amenities" : $scope.amenities,
"area": $scope.myDataBlurred,
"bathrooms" : $scope.bathrooms,
"bedrooms" : $scope.bedrooms,
"State": $scope.State,
"city": $scope.city,
"country" : $scope.country,
"current_property_status" :$scope.current_property_status,
"car_spaces" : $scope.car_spaces,
"expired" : $scope.expired,
"furnished" : $scope.furnished,
"floor_or_level" : $scope.floor_or_level,
"house_number" : $scope.house_number,
"notes" : $scope.notes,
"ofname" : $scope.ofname,
"pfname" : $scope.pfname,
"parking_type" : $scope.parking_type,
"pincode" : $scope.pincode,
"prop_avail_date" : $scope.prop_avail_date,
"prpty_owner_email_id" : $scope.prpty_owner_email_id,
"prpty_pm_email_id" : $scope.prpty_pm_email_id,
"prpty_registration_no" : $scope.prpty_registration_no,
"prpty_type" : $scope.prpty_type,
"sqft" : $scope.sqft,
"street_name" : $scope.sqft,
"verified" : $scope.verified,
"prpty_type_sub" : $scope.prpty_type_sub,
"published_on": $scope.published_on,
"profile": $scope.profile
/* "location" : $scope.location,
"phone" : $scope.phone */
};
var response = $http.post('/Owner/addprop', formData);
response.success(function(data, status, headers, config) {
$scope.list.push(data);
});
response.error(function(data, status, headers, config) {
alert( "Exception details: " + JSON.stringify({data: data}));
});
//Empty list data after process
$scope.list = [];
$scope.$setPristine();
};
}]);
</script>
var app=angular.module('formSubmit',[]);
app.controller('FormSubmitController',['$scope','$http',函数($scope,$http){
/*$scope.mydatablured=$scope.area*/
$scope.list=[];
$scope.headerText='AngularJS Post Form Spring MVC示例:在表单下方提交';
$scope.fuzzle=函数(){
$scope.mydatablured=$scope.area;
}
$scope.submit=函数(){
var formData={
“协议有效期”:$scope.agreement有效期,
“便利设施”:$scope.professionals,
“区域”:$scope.mydatablarred,
“浴室”:$scope.bathrooms,
“卧室”:$scope.卧室,
“状态”:$scope.State,
“城市”:$scope.city,
“国家”:$scope.country,
“当前属性状态”:$scope.current\u property\u status,
“车位”:$scope.car_spaces,
“过期”:$scope.expired,
“提供”:$scope.profected,
“地板或地板标高”:$scope.floor或地板标高,
“房屋编号”:$scope.house\u编号,
“注释”:$scope.notes,
“ofname”:$scope.ofname,
“pfname”:$scope.pfname,
“停车类型”:$scope.parking\u type,
“pincode”:$scope.pincode,
“项目可用日期”:$scope.prop\u avail\u date,
“prpty_所有者_电子邮件_id”:$scope.prpty_所有者_电子邮件_id,
“prpty_pm_email_id”:$scope.prpty_pmu email_id,
“注册号”:$scope.prpty\u注册号,
“prpty_类型”:$scope.prpty_类型,
“sqft”:$scope.sqft,
“街道名称”:$scope.sqft,
“已验证”:$scope.verified,
“prpty_type_sub”:$scope.prpty_type_sub,
“发布日期”:$scope.published_on,
“profile”:$scope.profile
/*“位置”:$scope.location,
“电话”:$scope.phone*/
};
var response=$http.post('/Owner/addprop',formData);
response.success(函数(数据、状态、标题、配置){
$scope.list.push(数据);
});
错误(函数(数据、状态、标题、配置){
警报(“异常详细信息:+JSON.stringify({data:data}));
});
//处理后的空列表数据
$scope.list=[];
$scope.$setPristine();
};
}]);
HTML
<div class="col-md-6">
<span> Location<i style="color: red;">*</i>
<div id="locationField">
<input id="autocomplete" name="property_loc"
placeholder="Search for location" onFocus="geolocate()"
type="text" class="form-control" value="${locn}" data-ng-model="area" ng-blur="blurred()" required></input>
</div>
</div>
地点*
使用此代码
它与谷歌地图API配合使用。首先在输入字段中键入城市名称
不要看警告和错误。如果你添加了一个API密钥,它就可以在没有警告和错误的情况下工作
var myApp=angular.module('myApp',[]);
myApp.directive('googleplace',function()){
返回{
要求:'ngModel',
链接:功能(范围、元素、属性、模型){
变量选项={
类型:[]
};
scope.gPlace=new google.maps.places.Autocomplete(元素[0],选项);
google.maps.event.addListener(scope.gPlace,'place_changed',function(){
作用域$apply(函数(){
模型.$setViewValue(element.val());
});
});
}
};
});
函数MyCtrl($scope){
$scope.gPlace;
}
您的位置是:{{chosenPlace}
使用此代码
它与谷歌地图API配合使用。首先在输入字段中键入城市名称
不要看警告和错误。如果你添加了一个API密钥,它就可以在没有警告和错误的情况下工作
var myApp=angular.module('myApp',[]);
myApp.directive('googleplace',function()){
返回{
要求:'ngModel',
链接:功能(范围、元素、属性、模型){
变量选项={
类型:[]
};
scope.gPlace=new google.maps.places.Autocomplete(元素[0],选项);
google.maps.event.addListener(scope.gPlace,'place_changed',function(){
作用域$apply(函数(){
模型.$setViewValue(element.val());
});
});
}
};
});
函数MyCtrl($scope){
$scope.gPlace;
}
您的位置是:{{chosenPlace}
感谢您回答Felix..抱歉,我的问题不完整..我正在使用angularjs表单..我想要angularjs相关的答案..请看您是否能帮我解决这个问题。在我的示例中,我将输入值设置为这一行中的google autocomplete值: