Angular.js 提交表单的旧方式 [英] Angular.js submit form old way

查看:28
本文介绍了Angular.js 提交表单的旧方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将一个旧的 html 页面从 jQuery 迁移到 Angular,它包含一些带有 的老式表单.当我使用 ng-app 指令丰富我的页面时,旧表单停止工作(我的意思是当你按下 submit 按钮时,什么也没有发生).

I'm migrating an old html page from jQuery to Angular, and it contains some old-school forms with <input type="submit">. When I enriched my pages with the ng-app directive, the old forms stopped working (I mean when you press the submit buttons then nothing happens).

我搜索了这个问题并扫描了 Angular 文档,但似乎没有人再提交表单了.

I searched for this problem and scanned the Angular docs too, but it seems that nobody is submitting forms anymore.

关于如何在不敲太多键的情况下让这些表单重新焕发生机的任何建议都将不胜感激.

Any suggestions on how to bring those forms to life again without much keystrokes would be appreciated.

目前表单有以下标记:

<form name="form_upload" method="post" action="" enctype="multipart/form-data">
<input type="file" name="file">
<input type="submit" name="send" value="Upload">
</form>

我清除了所有 jQuery 代码并重新开始使用 Angular.

All jQuery code I purged and starting fresh with Angular.

UPD:

我想我现在找到了原因,它是空的 action 属性,似乎空的动作不受标准的欢迎,但使用起来非常方便,允许您将表单提交到当前页面的 URL,是否有有角度的方法吗?

I guess i now found cause, it's empty action attribute, it seems empty action is not welcomed by standarts, but very convenient to use allowing you to submit form to the current page URL, is there Angular way to do it ?

推荐答案

离开文档:http://docs.angularjs.org/api/ng.directive:form

Angular 的理念是尽量减少数据和页面重新加载,因此他们不喜欢老式表单",但您可以通过在表单中​​使用 action 属性来绕过它.

Angular's philosophy is to minimize data and page reloads, so they don't like "old school forms", but you can get around it by using an action attribute in the form.

Angular 的设计考虑到了单页应用程序,并避免了整页重新加载,因为这需要更长的时间.通过使用 ngSubmit 指令,您可以定义一个函数来将表单数据发送到服务器并比重新加载整个页面更快地获得响应.字节而不是千字节.

Angular is designed with single page applications in mind and avoiding full page reloads as that is going to take longer to do. By using the ngSubmit directive, you can define a function to send over the form data to the server and get a response back much quicker than a full page reload. Bytes instead of Kilobytes.

这篇关于Angular.js 提交表单的旧方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆