Angular.js提交表单老办法 [英] Angular.js submit form old way
问题描述
我迁移从jQuery的一个旧的HTML页面,角,它包含了一些老派的形式与<输入类型=提交>
。当我丰富了我的页面使用了 NG-应用
指令,旧的形式停止工作(我的意思是,当你preSS的提交
按钮,然后什么也没有发生)。
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).
我搜索了这个问题,并扫描的文档角过,但似乎没有人提交表单了。
I searched for this problem and scanned the Angular docs too, but it seems that nobody is submitting forms anymore.
有关如何重新将这些形式的生活没有太多的按键将AP preciated任何建议。
Any suggestions on how to bring those forms to life again without much keystrokes would be appreciated.
目前的形式有以下标记:
Currently the form has following markup:
<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 code我清洗和开始角清新。
All jQuery code I purged and starting fresh with Angular.
UPD:
我想我现在发现的原因,它是空的动作
属性,似乎空的动作不是由standarts欢迎,但使用起来非常方便,让您提交的形式向当前页面的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'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.
角的设计充分考虑,避免完全重新加载页面作为单页的应用程序是要花费更长的时间做。通过使用 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屋!