【问题标题】:ng-include with ng-click raise submit - how to avoid it?ng-include 和 ng-click raise submit - 如何避免它?
【发布时间】:2015-12-27 16:39:50
【问题描述】:

我有 html 模板:

<div ng-controller="MyController">
  <form novalidate>
    Name: <input type="text" ng-model="user.name" />
    <button ng-click="greet(user)">GREET</button>
  </form>
</div>

我这样添加它:

"<div ng-include src=\"'/views/template.html'\"></div>"

这是MyController中的函数:

$scope.user = {}
    $scope.greet = function (user) {
        alert('hello ' + user.name)
    }

但是当我点击按钮时,它会提交它并不会调用 greet 函数。
我也尝试将type="button" 添加到它,但它是相同的。
Here is the working solution 所以我不知道我错过了什么。

【问题讨论】:

  • 我试过你提供的代码,我这边没有提交表单。可能在应用程序中,您有另一个强制提交表单的处理程序。

标签: angularjs angular-leaflet-directive


【解决方案1】:

将type="submit" 与提交按钮一起使用,并使用input 而不是button。

【讨论】:

  • 我试过它也可以回发。在我添加的示例中,它与我添加的代码相同。
  • 我在 plunker 中重新创建了这个场景,似乎工作正常:plnkr.co/edit/PEElwQLyTZRLK536pwFv?p=preview
  • 你说得对,它有效。这可能是该指令中模板和弹出窗口的一些问题。当我在没有模板的情况下尝试相同的代码时,它可以工作,但在模板中却不行。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-27
  • 1970-01-01
  • 1970-01-01
  • 2015-12-15
  • 1970-01-01
  • 2014-01-15
相关资源
最近更新 更多