Angular: Template Driven Forms - Enable submit button if at least one field is entered

爷,独闯天下 提交于 2021-01-28 06:12:26

问题


I have a simple form that has a set of fields and I want to enable the submit button if at least one field has been entered. I don't wanna use a Model Driven Form as I feel it's a overkill, given the scenario.

What is the simplest way to check if at least one field is not empty in Template Driven Forms?


回答1:


You can work with ngModel and ngModelChange.

In your html:

<input type="text" class="form-control" [(ngModel)]="yourvalue" (ngModelChange)="valueChanged()" />

In your component:

private valueChanged(){
  // enable sumbit button
}


来源:https://stackoverflow.com/questions/46665522/angular-template-driven-forms-enable-submit-button-if-at-least-one-field-is-e

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!