简体   繁体   English

提交按钮未触发模式

[英]Submit button is not firing the modal

The submit button should fire the 'check' function and also fire the bootstrap modal. 提交按钮应触发“检查”功能,并触发引导程序模式。 But the later is not happening. 但是后来没有发生。 It works when I change the html to type="button". 当我将html更改为type =“ button”时,它可以工作。 Isn't it possible to fire the bootstrap modal with a submit button? 是否有可能使用提交按钮来触发引导程序模式?

<form [formGroup]="guessForm" (ngSubmit)="check($event)" class="form-group">
    <input type="number" formControlName="answer" class="form-control">
    <button type="submit" [disabled]="!guessForm.valid" data-toggle="modal" [attr.data-target]="myModal" class="btn btn-success">Check</button>
</form>

This happens because a submit button refreshes the page by default. 发生这种情况是因为默认情况下, submit按钮会刷新页面。 Try to prevent it whith the following line of code. 尝试通过以下代码行阻止它。
$event.preventDefault();
Add this as first line in your check method. 在检查方法中将其添加为第一行。 It should work then. 那应该可以了。

At first you need to make a event than control submit button and fire modal as like below. 首先,您需要创建一个事件,而不是控制提交按钮和触发模式,如下所示。 I call it with jquery but you use your desired framework. 我用jquery称呼它,但是您使用了所需的框架。

<input type="submit" value="submit" onclick = "foo();"/>
<script>
    function foo(){
      $('#yourModalId').modal('show'); 
    }
</script>

For angular JS you may follow this link : http://plnkr.co/edit/wfv8P2T1ENg6XkjruzEq?p=preview 对于有角JS,您可以点击以下链接: http : //plnkr.co/edit/wfv8P2T1ENg6XkjruzEq?p=preview

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

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