I create a StackBlizt example to how do this:
https://stackblitz.com/edit/angular-hezrsa
Look at flatJson() Method.
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
public obj = {};
private startObj= {
id: 5,
date: "2018-05-05",
tmp: {
warranty: "no",
discount: "yes"
}
};
constructor(){
this.flatJson();
}
flatJson():void{
for (var prop in this.startObj) {
console.log(prop);
if(typeof this.startObj[prop] == 'object'){
for (var nestedprop in this.startObj[prop]) {
this.obj[nestedprop] = this.startObj[prop][nestedprop];
}
} else{
this.obj[prop] = this.startObj[prop];
}
}
}
}
hope i help you!