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.
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>