I currently have a drop down box on my HTML page that the users selects from. Once they select a choice like "Jeep" it will pass that to my component to then use this value. I am curious if it is possible to send back two separate variables at the same time. I would like to pass back their selection of "Jeep" as well as another value from the same JSON data set such as "Black".
Below is the code I use to get the "Jeep" into my component. Note the data is like this cars.
{name: "Jeep", color: "Black"}
cars.component.html
<p>Select Car</p>
<select class="form-control" (change)="changedCar($event)" >
<option value="">Select Car</option>
<option *ngFor="let car of cars" value="{{car.name}}">{{car.name}}/option>
</select>
cars.component.ts
changedCar (event: any) {
this.selectedName = event.target.value;
console.log(this.selectedName );
}
So currently I have this console.log producing "Jeep" as desired. Is it possible to send something so that I can have this.selectedColor
and it produce "Black"?
I am very new so I apologize if this is a bad question.
EDIT: Sorry for not adding enough detail at first. -- I wanted to keep it as simple as possible for a easy fix. I will now include all the details.
cars.component.ts more
ngOnInit() {
this.databaseService.getCar().subscribe(
cars => this.cars = cars
);
database.service.ts
export class Car {
car: string;
}
getCar(): Observable<Car[]> {
const url = 'http://localhost:3000/car';
const data = ({
});
return this._http.post(url, data)
.pipe(
map((res) => {
console.log(res);
return <Car[]> res;
})
);
}