作者:凰千寻_847 | 来源:互联网 | 2023-09-12 11:00
MY Http request looks like this
MY Http请求看起来像这样
$scope.getData = function() {
$http.get("/Services/JoppdService.svc/getKombiImport/" + $scope.fromDate + "/" + $scope.untilDate + "/" + $scope.airport)
.success(function (response) {
$scope.education = response;
});
}
After submiting i have request in console that looks like this
提交后我在控制台中有这样的请求
http://localhost:8080/Services/JoppdService.svc/getKombiImport/undefined/undefined/undefined
dateFrom, dateUntil and airport is not binded. Where is problem ?
dateFrom,dateUntil和airport没有绑定。哪里有问题?
3 个解决方案
1
Use ng-submit
, bind the required parameters into an object obj
, like obj.fromDate
, obj.untilDate
, and obj.airport
in the form. Use button type as submit
使用ng-submit,将所需参数绑定到对象obj中,如表单中的obj.fromDate,obj.untilDate和obj.airport。使用按钮类型作为提交
Your html would transform into,
你的HTML会变成,
Pass obj
in ng-submit
method getData()
which now looks like, getData(obj)
在ng-submit方法getData()中传递obj,现在看起来像,getData(obj)
You got to convert the fromDate and untilDate into String. Have a look at this. Replace convertToString()
below with the solution mentioned in that link.
你必须将fromDate和untilDate转换为String。看看这个。使用该链接中提到的解决方案替换下面的convertToString()。
Then in your controller getData()
would look like,
然后在你的控制器getData()看起来像,
$scope.getData = function(obj) {
var fromDate = convertToString(obj.fromDate);
var untilDate = convertToString(obj.untilDate);
var airport = obj.airport;
$http.get("/Services/JoppdService.svc/getKombiImport/"+fromDate+"/"+untilDate+"/"+.airport)
.success(function (response) {
$scope.education = response;
});
}
Also, do not have empty spaces (" ") while forming URLs.
此外,在形成URL时不要有空格(“”)。
If you want to initialize anything, use ng-init
like this
如果要初始化任何内容,请像这样使用ng-init