简体   繁体   English

角度形式双重发布(HTML中没有另一个ng-controller)

[英]Angular form double posting (not having another ng-controller in the html)

this bites me too, like many others I have a simple ng-form (: cleared for bravity) in a partial: 这也咬我,就像其他许多人一样,我有一个简单的ng-form(:为勇敢而清除)的一部分:

<form ng-submit="functionName()">


                   <input type="text" class="postField" ng-model="model.text" required ng-maxlength=200 />
            <button class="postBT" ng-click="functionName()" ng-class="BToverclass" ng-mouseover="BToverclass = 'overShadow'" ng-mouseleave="BToverclass=''">Post</button>
            </div>

            </form>

for some reason every form submit, we get 2 posts to the controller, with all the data doubled. 由于某种原因,每个表单提交后,我们都会向控制器发送2条帖子,所有数据都翻倍。 I checked and the specific controller doesn't appear in the html, but only in the route. 我检查了一下,特定的控制器没有出现在html中,而只出现在路由中。 Any idea what I'm missing? 知道我缺少什么吗?

Thanks! 谢谢!

You have both an ng-click() calling functionName() and a call to it from ng-submit . 您既有一个调用functionName()ng-click() functionName() ,也有一个从ng-submit对其进行的调用。 Each results in a call to your function. 每个都会调用您的函数。 You only want the submit one. 您只想要提交一个。

FYI, you also have a </div> with no opening <div> for it to close. 仅供参考,您还有一个</div> ,没有打开<div>即可关闭它。

Here's working code: 这是工作代码:

  <form ng-submit="functionName()">
      <input type="text" class="postField" ng-model="model.text" required ng-maxlength=200 />
      <button class="postBT" ng-class="BToverclass" ng-mouseover="BToverclass = 'overShadow'" ng-mouseleave="BToverclass=''">Post</button>

   </form>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM