Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

510
Visualizações
How to check and disable a checkbox, when other 3 checkbox are checked, in Angular

HTML code (with 4 checkboxes in formArray) :

( I am getting disabled and checked as true, in console, but is unable to reflect it in UI , i.e check and disable the first checkbox on UI, on selection of other three checkboxes)

<div formArrayName="permissionForm">
  <div *ngFor="let subModule of permissionForm.value; let i = index" [formGroupName]="i">
    <input type="text" readonly formControlName="moduleGroupName" class="input-border-module" style="margin-top: 5px;" />
    <br />

    <label class="col-md-5 text-left">
                <input
                  type="text"
                  readonly
                  formControlName="subModules"
                  class="input-border-submodule"
                />
     </label>
    <input type="checkbox" formControlName="view" id="view1" />
    <input type="checkbox" formControlName="add" id="add"(change)="isCheckedAdd($event)"/>
    <input type="checkbox" formControlName="edit" (change)="isCheckedEdit($event)" />
    <input type="checkbox" formControlName="delete" (change)="isCheckedDelete($event)"/>
  </div>
</div>

TS Code : (Here add, edit and delete are boolean values) ( I am getting disabled and checked as true, in console, but is unable to reflect it in UI , i.e check and disable the first checkbox on UI, on selection of other three checkboxes)

isCheckedAdd(event) {
  let x = < HTMLInputElement > document.getElementById("view1");
  this.add = true;
  if (this.add == true && this.edit == true && this.delete == true) {
    x.checked = true;
    x.disabled = true;
  }
}

isCheckedEdit(event) {
  let x = < HTMLInputElement > document.getElementById("view1");
  this.edit = true;
  if (this.add == true && this.edit == true && this.delete == true) {
    x.checked = true;
    x.disabled = true;
  }
}

isCheckedDelete(event) {
  let x = < HTMLInputElement > document.getElementById("view1");
  this.delete = true;
  if (this.add == true && this.edit == true && this.delete == true) {
    x.checked = true;
    x.disabled = true;
  }
}

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can use disable() method of FormControl.

The code should be like the following

In HTML,

<input type="checkbox" formControlName="add" id="add"(change)="isCheckedAdd(i)"/>

In TS,

isCheckedAdd(i: number) {
  const permissionFormControls = this.form.controls.permissionForm as FormArray; // Not sure what the name of FormGroup you are using but I assume it's "form"
  permisionFormControls[i].controls.edit.disable();
  permisionFormControls[i].controls.delete.disable();
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda