I am trying to add new properties inside the josn data without adding in the interface. But i am not able to add it.So, How to add new properties in the json data. Is it possible or not?
app.component.ts:
export class AppComponent {
data1: Candle[] = [
{
name: 'john',
place: 'forest',
phone: '124-896-8963'
},
{
name: 'Jay',
place: 'City',
phone: '124-896-1234'
},
{
name: 'Joseph',
place: 'sky',
phone: '124-896-9632'
},
];
foo() {
const modifiedData = this.data1.map(d => {
d.expanded1 = false; // error!
//~~~~~~~~~ Property 'expanded1' does not exist on type 'Candle'.
d.expanded2 = false; // error!
//~~~~~~~~~ Property 'expanded2' does not exist on type 'Candle'.
return d;
});
console.log(modifiedData);
}
}
interface Candle {
name: string,
place: string,
phone: string
}
Object.assign()
like this. Does that meet your needs? If so I'll write up an answer explaining; if not, what am I missing?