Reputation: 22946
I have to disable this button if no checkbox is selected.
<button (click) = "onDeleteSelected()"
[disabled] = "mflagDisableMoveTo.value"> Delete selected </button>
In typescript I have:
mflagDisableMoveTo = new FormControl( { value: 'true' } )
This form control is not a part of any formGroup.
Where am I supposed to put [formControl] = "mflagDisableMoveTo"
in the above HTML code?
How to use formControl
to disable an individual button?
Upvotes: 0
Views: 889
Reputation: 87
Good day: The formControl has to have a false initial value, what I did is use the value of the formControl in the disabled button:
1.Create my formControl in app.component.ts
import { FormControl, Validators } from "@angular/forms";
check = new FormControl(false, [Validators.required]);
2.app.component.html
<input type="checkbox" [formControl]="check" />
<button (click)="showControl()" [disabled]="check.value === false">Send</button>
Upvotes: 1
Reputation: 250
At first, true is not a string, so you need to write true, not 'true'
mflagDisableMoveTo = new FormControl({ value: true })
You can get any FormControl value by: FormControl.value
Since you have new FormControl({ value: true }), right answer is: mflagDisableMoveTo.value.value
<button (click)="onDeleteSelected()" [disabled] = "mflagDisableMoveTo.value.value"> Delete selected </button>
Upvotes: 2