Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any way to check or not the checkbox according to the value that arrives? Angular

When the data arrives directly, the table is filled in, and I cannot tell you that if "A" arrives it is checked and if "D" arrives, no.

 re(ref: getrefactormodel, contador:number){
      let datos= this.fb.group({
           word_to_rename: [ref.word_to_rename, Validators.required],
           renowned_word: [ref.renowned_word, Validators.required],
           name:[ref.name, Validators.required],
           id:[ref.id, Validators.required],
           activecheck:[ref.activecheck, Validators.required]
         });
       this.refactorFormGroupItemsArray.insert(contador,datos);
   }

Like there is some way to put in the input that if value is A be checked if it is D no.

<input  type="checkbox"  formControlName="activecheck" value="D" />
like image 394
Maria Gálvez Avatar asked Nov 27 '25 03:11

Maria Gálvez


1 Answers

checkbox is true/false value even you have set as string when you change it again the value will be either false or true.

 re(ref: getrefactormodel, contador:number){
      let datos= this.fb.group({
           word_to_rename: [ref.word_to_rename, Validators.required],
           renowned_word: [ref.renowned_word, Validators.required],
           name:[ref.name, Validators.required],
           id:[ref.id, Validators.required],
           activecheck:[ref.activecheck == 'D' ? true : false , Validators.required]
         });
       this.refactorFormGroupItemsArray.insert(contador,datos);
   }

demo 🚀

some angular component libraries has a components like checkbox the behave the way you want I been use primeng check their component here

like image 120
Muhammed Albarmavi Avatar answered Nov 28 '25 17:11

Muhammed Albarmavi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!