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

189
Visualizações
Set value of local iteration scoped variable in angular 2

I have the below HTML in Angular

<span *ngIf="ControllerType?.AttributeID =='Controller Type'">                                            
    <select multiple name="ControllerType.Default" [(ngModel)]="ControllerType1">
        <option *ngFor="let z of ControllerType.Options" value={{z.OptionID}}>
            {{z.OptionID}}
        </option>
    </select>
</span>

What I want to know is how can I set ControllerType.Default which is of type string to get the values selected in ControllerType1. So whatever values were selected and stored in ControllerType1 should also be stored in ControllerType.Default

Doing this {{ControllerType.Default=ControllerType1;""}} after the Select tag and inside the iteration just errors out.

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

0

use the expression inside the ngModelChange

<span *ngIf="ControllerType?.AttributeID =='Controller Type'">
   <select multiple name="ControllerType.Default" [(ngModel)]="ControllerType1"  (ngModelChange)="ControllerType.Default = ControllerType1">
   <option *ngFor="let z of ControllerType.Options" value={{z.OptionID}}>
      {{z.OptionID}}
   </option>
   </select>
</span>

updated

create and ngInit directive and call it in the HTML

@Directive({
  selector: 'ngInit',
  exportAs: 'ngInit'
}) 
export class NgInit {
  @Input() values: any = {};

  @Input() ngInit;
  ngOnInit() {
    if(this.ngInit) { this.ngInit(); }
  }  
}

assign the expression under ngInit directive

[ngInit]="ControllerType1 = ControllerType.Default"

  <span [ngInit]="ControllerType1 = ControllerType.Default"  *ngIf="ControllerType?.AttributeID =='Controller Type'">
       <select multiple name="ControllerType.Default" [(ngModel)]="ControllerType1"  (ngModelChange)="ControllerType.Default = ControllerType1">
       <option *ngFor="let z of ControllerType.Options" value={{z.OptionID}}>
          {{z.OptionID}}
       </option>
       </select>
    </span>
over 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