简体   繁体   English

Angular 2动画导致页面重新加载

[英]Angular 2 animation cause page to reload

I have 我有

<div class="style1" *ngIf="data" [@slideInLeft]="slideInLeft">
  <form [formGroup]="form1" class="form" *ngIf="form1">
....
     <button [disabled]="this.isUpdating === true" type="submit" class="btn btn-default" (click)="cancelClicked()">Cancel</button>
  </form>
</div>

import { slideInLeft } from 'ng-animate';

animations: [trigger('slideInLeft', [transition('* => *', useAnimation(slideInLeft))])]

When I the form is shown animation work fine. 当我显示表格时,动画工作正常。 As soon as I click cancel the page reloads. 单击取消后,页面将重新加载。

If I remove animations completely cancel does not reload page. 如果我完全删除动画,则不会重新加载页面。

Does anyone knows why this happens? 有谁知道为什么会这样吗?

If you had a stackblitz or something to reproduce the issue, I think I could test my theory. 如果您遇到了重击或重现该问题的方法,我认为我可以验证我的理论。 I am guessing it could have something to do with the fact you have the cancel button's type attribute as "submit". 我猜想这可能与您将取消按钮的type属性设为“提交”有关。 That is contradictory of how forms naturally work, the submit button should submit the form, not cancel. 这与表单的自然工作方式矛盾,“提交”按钮应该提交表单,而不是取消表单。

In a plain html the submit button performs whatever is defined by the action attribute, take a look here https://www.w3schools.com/html/html_forms.asp 在纯HTML中,提交按钮将执行action属性定义的所有操作,请在此处查看https://www.w3schools.com/html/html_forms.asp

The first thing I would try is to make the cancel button's type attribute "button", so <button type="button> and see if that helps. If you want to handle the submit action via the angular way, you should handle that via <form (ngSubmit)="takeSomeAction()"> 我要尝试的第一件事是使cancel button的type属性为“ button”,所以<button type="button>并查看是否有帮助。如果您想通过角度方式处理Submit操作,则应通过<form (ngSubmit)="takeSomeAction()">

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

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