Angular ng包括表单操作Post URL不起作用

时间:2015-10-29 05:05:40

标签: javascript jquery html angularjs forms

如果使用ng-include将表单帖子包含在父html中,则不会触发表单帖子。

<div ng-include src="'form.html'"></div>

form.html文件代码如下

<form action="next/login" method ="post">
    <table>
        <tr>
            <td class="login_input_field v_align_top">
                <input type="text" name="email" ng-model="email">
            </td>
            <td class="login_input_field">
                <input type="password" name="pass" ng-model="password">
            </td>
            <td class="login_button_container">
                <button type="submit" id="login" name="login">Login</button>
            </td>
        </tr>
    </table>
</form>

如果我在表单中进行提交,则不会在浏览器的网址栏中导航该网址。不对提交事件执行任何操作。

请解释功能背后的角度逻辑。

不包含模板。

问题:

表单提交行为更改 示例html页面:index.html 1)我在index.html页面中有一个表单并提交它改变我的URL然后页面刷新并获得响应 2)如果我在模板中有表单并将其包含在index.html中。网址不会改变,页面也不会刷新。

第1点和第2点有什么区别?

3 个答案:

答案 0 :(得分:2)

您正在尝试使用div中的ng-include,如下所示。

<div ng-include src="'form.html'"></div>

但是,对于使用ng-includesrc属性,请将其用作下面的单独元素。

<ng-include
  src="string"
  [onload="string"]
  [autoscroll="string"]>
</ng-include>

使用ng-include和div使用如下:

<div ng-include="form.html"></div>

要将ng-include用作单独的元素,请使用以下代码:

<ng-include src="form.html"></ng-include>

答案 1 :(得分:0)

要更改代码而不是以下内容:

<div ng-include="" src="'form.html'"></div>

答案 2 :(得分:0)

我为此创建了plunk

<div ng-include="'form.html'"></div>

有效,J.M.Farook的回答也是如此

<div ng-include="" src="'form.html'"></div>