3
I receive the Customer class in my form
import { NgSelectOption } from '@angular/forms';
export class Cliente {
nome: string = '';
carros: any [] = [
{ id: 1, modelo: 'Gol',selected:false },
{ id: 2, modelo: 'Saveiro',selected:true },
];
}
ngOnInit() {
this.cliente = new Cliente();
}
I want to leave the option preset when the value Selected is true.
<select [(ngModel)]="cliente.carros" name="cliente.carros" >
<option *ngFor="let c of cliente.carros" [selected]="c.selected" [value]="c.id">
{{c.modelo}}
</option>
</select>
But when I do this without the name="" property the value is not passed to the Submit in my form
Follow below the image like this now.
Follow the project link https://stackblitz.com/github/CristovaoTorres/AngularCrudTest
It’s kinda weird, you’re trying to throw the value back into
cliente.carros
, tries to point out the[(ngModel)]=
for another variable, for examplecarrosSelecionados
– edson alves