I have an array coming from @input like this:
export interface XXModel {
id: number;
category: string;
serialNumber: string;
description: string;
}
@Input() assets: XXModel[];
I created another array to get the Id and description from the previous array to use this array to provide data to a component in the html
public _assets:{key:number, value:string}[];
how can I fill the _assets array with id and description from the assets array to populate component in html receive data from _assets array .
I tried this approach but I get undefined and its not working:
@Input() assets: XXModel[];
public _assets:{key:number, value:string}[];
ngOnInit() {
this.assets.map(item => {
if(item){
const {id, description} = item;
this._assets.push({key:id, value:description});
}
});
console.log(this._assets)
}
also I tried this way :
@Input()
get assets(): MaintenanceAssetModel[] {
return this._assets as any
}
set assets(value: MaintenanceAssetModel[]) {
value.map(asset=>{
this._assets.push({key:asset.id,value:asset.description})
})
}
public _assets: {key:number, value:string}[];