Hi, I've done a couple of tests in Angular 2, and I'd like to resolve a question.
Right now I'm working with a simple select, and I'm trying to receive a JSON object by making a selection in it.
WORKS It works if I want to receive only a part of the JSON (attached an example):
JSON
export class Coche{
nombre: String;
dueños: [{
nombre: String;
}];
vendedores: [{
nombre: String;
}];
}
If I do the following, it works: HTML
<select #coche (change)="getCoches(coche.value);" >
<option type="text" *ngFor="let coche of coches" value="{{coche.nombre}}" >{{coche.nombre}}</option>
</select>
TS
getCoches(nombre: string): void {
console.log(scenario);
}
DOES NOT WORK But if I do the following, no:
HTML
<select #coche (change)="getCoches(coche.value);" >
<option type="text" *ngFor="let coche of coches" value="{{coche}}" >{{coche.nombre}}</option>
</select>
TS
getCocches(coche: Coche): void {
console.log(coche);
}
The difference is that I send a complete object (car) and not an element of it (car.name). Any solution?