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

326
Visualizações
Angular ngModelChange parameter function different to $event
I want to send a different parameter to the $event in the function:


 <div class='col-sm'>
      <label class="col-3 col-form-label">Origen</label>
          <div class="col-4">
              <select [(ngModel)]="dana" class="form-control"  
                 (ngModelChange)="filterFor($event)"required>
                   <option *ngFor="let dano of danos" 
                       [value]="dano.comment">{{dano.make}}
                   </option>
             </select>
          </div>
     </div>

I would like to send the parameter in the function filterFor call:

    <div class='col-sm'>
         <label class="col-3 col-form-label">Origen</label>
             <div class="col-4">
                 <select [(ngModel)]="dana" class="form-control"  
                     (ngModelChange)="filterFor(dano.tipo)"required>
                   <option *ngFor="let dano of danos" 
                        [value]="dano.comment">{{dano.make}}
                   </option>
                 </select>
             </div>
       </div>

Fails:

error TS2551: Property 'dano' does not exist on type 'ComunidadFiltracionesComponent'. Did you mean 'danos'? .

Do you know the format of the parameter so that it accepts it? Thanks in advance

Expand the query:

I have an object with different parameters:

let car = [ {'make': 'Ford', 'comment': 'The vehicle has a heavy internal combustion engine....'}];

In dropdown (ngFor), when the customer selects the make of the car, we take the comment variable.

If I want to compare vehicles:

if (dana == 'The vehicle has a heavy internal combustion engine....'){
this.quality = 'goog';
}

To find out which brand the client has entered, I have to compare through the comment (too long). I want to compare by the brand variable:

if (dana == 'Ford'){
this.quality = 'goog';
}

See in stackblitz : https://angular-ivy-mu5mrh.stackblitz.io/

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

0

if you use (ngModelChange)="filterFor($event)" in your function filterFor you received the [value] of the option selected.

if you use as value [value]="dano.make"

You can use some like

filterFor(value:any){
   this.data=value; //<--if not use [(ngModel)] else [ngModel]
                    //don't forget equal the variable to value

   const dano=this.datos.find(x=>x.make==value)
   console.log(dano) //<--here you has the whole object
   //you can, e.g.
   if (value=='Ford')....
   //or
   if (dano.comment=='The vehicle has a heavy internal..')...
}
about 4 years ago · Santiago Trujillo Relatório

0

the issue in your code is that your'e trying to access dano variable which is out of the loop scope and hence isn't being recognized

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