问题
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