How can I disable the button if the input is empty, and enable it when the user start typing in the input, i tried that:
<input #new_field type="text" autocomplete="off" />
<p-button (onClick)="saveNewField(new_field.value)" [disabled]="new_field.value ==''" label="Save"></p-button>
and also this:
<input [(ngModel)]="searchText" size="30" autocomplete="off" />
<p-button (onClick)="saveNewField(searchText)" [disabled]="!searchText" label="Save"></p-button>
You can use ngModel for two way binding.There is no need to call the form.Simply call below.
Also declare the variable some in component to bind the value.
ex: some:any;
Fill all input then button will be enabled
you have form tag then try this
I was looking at the same issue for a while. Finally find something that worked for me. Try this:
HTML
TS
If this doesn't work, also create a model and call searchText in the model.
Try this
Use ngModel and bind a value and use to disable button. Try this:
Typescript file:
HTML part
TS part:
EXPLANATION
You should add validation for your components and set check
is form validated
. In my example above if Component 2 input field is empty your form will be invalidated and button disabled.