【问题标题】:Angular ng include form action Post URL isn't workingAngular ng包含表单操作发布URL不起作用
【发布时间】:2016-01-29 03:02:08
【问题描述】:

如果使用 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>

如果我以表单形式提交,则 URL 不会在浏览器的 URL 栏上导航。没有对提交事件执行任何操作。

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

这与包含模板无关。

问题:

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

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

【问题讨论】:

  • 为什么是“'form.html'”?它不应该是:“form.html”吗?注意你的 ' (单引号)。
  • "form.html" 将行为具有范围变量。当您与“'form.html'”绑定时,它将充当字符串并搜索匹配的模板名称
  • 你可能应该选择

标签: javascript jquery html angularjs forms


【解决方案1】:

您正在尝试在 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>

【讨论】:

  • 有什么区别,因为当我在包含的 html 模板中提交表单。浏览器中的 URL 不会改变。如果我直接在 html 中给出提到的 url 更改,而不是 ng-include 表单提交? ng-include(内部表单提交)或直接表单(表单提交)之间有什么秘密?
【解决方案2】:

更改您的代码而不是如下:

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

【讨论】:

    【解决方案3】:

    我为此创建了一个plunk

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

    有效,J.M.Farook 的回答也有效

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

    【讨论】:

      猜你喜欢
      • 2018-12-06
      • 2015-04-18
      • 1970-01-01
      • 2017-09-17
      • 1970-01-01
      • 2014-01-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多