Angular2 - 如何使第二个按钮成为提交按钮
Angular2 - How to make the second button be the submit button
假设我有一个表单,其中有一个取消按钮和一个提交按钮。我希望取消按钮出现在验证按钮的左侧。当您按 "Enter" 时,它应该触发提交按钮,而不是取消按钮。 Angular2 的工作方式,第一个按钮总是由 "Enter" 键触发的按钮。
<button (click)="onCancel()">Cancel </button>
<button> (click)="onSubmit()">Submit</button>
在此示例中,将点击取消按钮而不是提交。如何让提交按钮触发,同时仍然保持相同的顺序?
A button element with no type attribute specified represents the same
thing as a button element with its type attribute set to "submit".
所以我会添加 type="button"
属性来取消按钮:
<button type="button" (click)="onCancel()">Cancel </button>
^^^^^^^^^^^^^
<button> (click)="onSubmit()">Submit</button>
假设我有一个表单,其中有一个取消按钮和一个提交按钮。我希望取消按钮出现在验证按钮的左侧。当您按 "Enter" 时,它应该触发提交按钮,而不是取消按钮。 Angular2 的工作方式,第一个按钮总是由 "Enter" 键触发的按钮。
<button (click)="onCancel()">Cancel </button>
<button> (click)="onSubmit()">Submit</button>
在此示例中,将点击取消按钮而不是提交。如何让提交按钮触发,同时仍然保持相同的顺序?
A button element with no type attribute specified represents the same thing as a button element with its type attribute set to "submit".
所以我会添加 type="button"
属性来取消按钮:
<button type="button" (click)="onCancel()">Cancel </button>
^^^^^^^^^^^^^
<button> (click)="onSubmit()">Submit</button>