My JSON structure looks like this:
{
"id": 1,
"name": "Marks, Price and Conn",
"description": "Newton",
"installations": [
{
"id": "1",
"name": "ENIM",
"key": 106789,
}
]
}
And when in my angular page I click on the client I want to add an installation. How to get current client values and then add a new object to subarray?
I tried simple
export class AddInstallationComponent implements OnInit {
clients: any;
client = {
name: '',
nip: '',
description: '',
installation: [{
name: '',
key: '',
}]
};
constructor(private clientService: ClientService) { }
saveInstallation(): void {
const data = {
name: this.client.installation['name'],
key: this.client.installation['key'],
};
this.client.installation.push(data)
}
}
But I don't know how to get values for my current client which I clicked.
this.client.installation['name']you useinstallationas an object. Herethis.client.installation.push(data)you use it like an array and... on the json file you have a different name:installations.