Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

190
Views
Establecer el valor de la variable de ámbito de iteración local en angular 2

Tengo el siguiente HTML en 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>

Lo que quiero saber es cómo puedo configurar ControllerType.Default , que es de tipo cadena para obtener los valores seleccionados en ControllerType1 . Por lo tanto, los valores seleccionados y almacenados en ControllerType1 también deben almacenarse en ControllerType.Default

Hacer esto {{ControllerType.Default=ControllerType1;""}} después de la etiqueta Seleccionar y dentro de la iteración simplemente genera errores.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

use la expresión dentro de 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>

actualizado

crear y directiva ngInit y llamarlo en el HTML

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

asignar la expresión bajo la directiva ngInit

[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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!