禁用按钮Angular2

时间:2018-08-10 06:49:19

标签: angular

当我的用户确实单击保存->

时,我想在Angular中禁用按钮

HTML->

 <form #myForm="ngForm" (ngSubmit)="save(myForm)">

 <button class="btn btn-sm btn-success" [disabled]="myForm.form.pristine">Save</button>

.ts

 save(myForm: NgForm) {
    myForm.form.pristine;
}

然后,如果我的用户确实更改了表单,则需要激活我的按钮。

Error->
{
    "message": "unused expression, expected an assignment or function call (no-

1 个答案:

答案 0 :(得分:1)

[disabled]="myForm.form.pristine"是什么意思? @Input() disabled: boolean //Whether the component is disabled.

<form #myForm="ngForm" (ngSubmit)="save(myForm)">

 <button class="btn btn-sm btn-success" [disabled]="isDisbled">Save</button>