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

282
Visualizações
How to reset second select box options to default value if we changes options in first select box using Angular

Have two selectboxes, if we select item in first select box and select one option in second select box. And If we select another option in first select box, need to reset back to default value like 'Select Time'. I tried using below code, I can able to select but unable to reset to back to default value, still selecting previously selecting value.

 public validTime = ['8', '9', '10', '11', '12', '1', '2', '3', '4'];
  public validTimeOptions = this.validTime;
  output = "....";

  selectedFood: string;

  foods = [
    {value: 'product10', viewValue: 'Monday'},
    {value: 'product20', viewValue: 'Tuesday'},
    {value: 'product30', viewValue: 'Wednesday'},
    {value: 'product40', viewValue: 'Thursday'},
    {value: 'product40', viewValue: 'Friday'},
  ];


  onFoodSelection() {
    this.output = this.selectedFood;
    this.validTime = this.validTime;
  }

HTML:

  <select placeholder="Favorite food" [(ngModel)]="selectedFood" (ngModelChange)="onFoodSelection()">
    <option *ngFor="let food of foods" [value]="food.value">
       {{ food.viewValue }}
    </option>
  </select>


  <select id="suspensionTime" class="kite-form-control" (click)="changeTimeUpdate()">
    <option [ngValue]="null" selected disabled>Select Time</option>
    <option *ngFor="let time of validTimeOptions" [ngValue]="time">{{ time }}</option>
  </select>

Stackblitz

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

0

You need to link suspensionTime select with an ngModel in order to update the value on day change.

// app.component.ts
selectedTime: string;
onFoodSelection() {
  this.output = this.selectedFood;
  this.validTime = this.validTime;
  this.selectedTime = null;
}

// app.component.html
<select id="suspensionTime" class="kite-form-control" (click)="changeTimeUpdate()"
[(ngModel)]="selectedTime">

Check this Stackblitz.

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