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

175
Visualizações
How to select only one div at a time in angular 10

I have to create a sort filter in my application where I can select only one option at a time to sort my results. My UI is such that I can not use checkboxes. It is simple list. So I am creating the list through div. Can anyone suggest how to impleenter image description herement selection and deselection of div in angular. I can select only one div at a time. Also If I have selected any option and now i click on option 2 then option 1 div should get de-selected and option 2 div should get selected.

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

One solution would be to set the 'current' value when the div is clicked. Add a class when the 'current' value matches the item's value.

<div *ngFor="let item of items" 
(click)="onItemSelection(item) 
[class.current-selection]="item === currentValue">
   {{ item }}
</div>

Handle the event in your component.ts file by storing the new value:

currentValue: string;

onItemSelection(newValue: string) {
   this.currentValue = newValue;
}

Then update the look of the current item in your component.scss file:

.current-selection {
  background-color: green;
}
about 4 years ago · Santiago Trujillo 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