Javascript Angularjs:ng模型绑定不';在第一个AJAX请求之后无法工作
我正在通过angularjs发出发帖请求Javascript Angularjs:ng模型绑定不';在第一个AJAX请求之后无法工作,javascript,angularjs,Javascript,Angularjs,我正在通过angularjs发出发帖请求 <input class="form-control" ng-model="hotel.hotel_name" type="text"> <input class="form-control" ng-model="hotel.hotel_loc" type="text"> <input type="button" value="Submit" name="Submit" ng-click="addHotel(hote
<input class="form-control" ng-model="hotel.hotel_name" type="text">
<input class="form-control" ng-model="hotel.hotel_loc" type="text">
<input type="button" value="Submit" name="Submit" ng-click="addHotel(hotel)" class="btn btn-sm btn-primary">
数据处理成功后,清除旧表单数据$scope.hotel=[]
但是,当我重新提交表单时,其中包含一些无法读取的值,我将得到undefined
$scope.addHotel=function(hotel){
//undefiend
console.log(hotel);
}
注:
第一次post请求和响应成功,但之后无法执行您正在将
酒店设置为阵列
。您应该将其设置为object
$http({
method:"POST",
data:{'hotel':hotel},
url:base_url+'operator/hotel/add_hotel'
}).then(function serverResponse(response){
//clear the old form data
$scope.hotel={}; //this is what you should do
});
或者将其设置为空字符串
$scope.hotel.hotel_name = '';
$scope.hotel.hotel_loc = '';
您是否在scope
object上定义了hotel
?hotel是一个对象而不是数组将其更改为$scope。hotel={}@user2181397:视图中的标记是that@Paritosh视图中的标记是什么意思that@user2181397:视图的控制器
,请参见ng model=“hotel.hotel\u name”
创建$scope.hotel={hotel\u name:undefined}
。我们不需要在controller
code中单独定义它。
$scope.hotel.hotel_name = '';
$scope.hotel.hotel_loc = '';