Currently working with angular 6 and have a method like this:
public Save(): void {
this.data.station.parkingSlot.forEach(p => {
if(p.isAvailable){
p.isAvailable = false;
this._carService.addCar(this.data);
return true;
}else{
alert("all parking lots are taken")
}
})
}
Looking to send the updated data (this.data) with isAvailable set to false as a parameter inside this._carService.addCar(this.data).
Below you can see how the this.data object looks. Notice that the last property isAvailable from parkingSlot is not updated to false as expected.
{
"id": 3,
"carType": "Spinter",
"plateNumber": "BUS-XXX-XXX",
"station": {
"id": 2,
"name": "STATION_2",
"longitude": 3,
"latitude": 4,
"city": "Oslo",
"streetName": "street1",
"houseNumber": 55,
"zipCode": 31000,
"parkingSlot": [
{
"id": 1,
"name": "PARKING_1",
"isAvailable": false
},
{
"id": 2,
"name": "PARKING_2",
"isAvailable": false
},
{
"id": 3,
"name": "PARKING_3",
**"isAvailable": true**
}
]
}
}
Desired output:
{
"id": 3,
"carType": "Spinter",
"plateNumber": "BUS-XXX-XXX",
"station": {
"id": 2,
"name": "STATION_2",
"longitude": 3,
"latitude": 4,
"city": "Oslo",
"streetName": "street1",
"houseNumber": 55,
"zipCode": 31000,
"parkingSlot": [
{
"id": 1,
"name": "PARKING_1",
"isAvailable": false
},
{
"id": 2,
"name": "PARKING_2",
"isAvailable": false
},
{
"id": 3,
"name": "PARKING_3",
**"isAvailable": false**
}
]
}
}
Seeking a solution to achieve this. Tried various approaches found through Google searches without success. Appreciate any help!
Additionally, I