热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

AngularJS表单未绑定到$http请求-AngularJSformisnotbindingto$httprequest

<formnovalidate><div

 
                

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


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

#2


0  

You would need to wrap your content inside if you have not already Also you should use for date inputs

如果您还没有将内容包装在内,您还需要将其用于日期输入

#3


0  

You must use ng-init to initialize these values like ng-init="fromDate = 0".

必须使用ng-init初始化这些值,如ng-init =“fromDate = 0”。

You could also just declare these variables at the begining of your controller such as $scope.fromDate = 0;

您也可以在控制器的开头声明这些变量,例如$ scope.fromDate = 0;


推荐阅读
author-avatar
凰千寻_847
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有