mercredi 13 avril 2022

Inverse the angular checkbox default values

I need to inverse the default values of checkbox. For eg. if checkbox is checked it sends the value as boolean true but i want to send value as false and vice versa.

Also if i assign the value as false in angular reactive form initialization the checkbox should be in checked state and if i assign true, checkbox should not be checked. I cannot figure out any solution, any help would mean a lot. Thanks.

Here is the code I am working on

component.html

<form [formGroup]="featureForm" (ngSubmit)="onSubmit()">
    <div class="form-group">

   <input type="checkbox" formControlName="featured" id="featured">
   <label for="featured" id="check1"> Checkbox 1</label><br>

   <input type="checkbox" formControlName="addons" id="addons">
   <label for="addons" id="check2"> Checkbox 2</label><br><br>

   <button>Send</button>
</div>
</form>

component.ts file

featureForm:FormGroup
this.featureForm=this.fb.group({
    featured:[false,Validators.required],
    addons:[false,Validators.required],
});



Aucun commentaire:

Enregistrer un commentaire