How to add dynamic properties in json response of api in Angular?
Answers (1)
Add AnswerTry this solution may it helps you to come out.
Example:
const link = "/assets/info-response.json"; newObject=[]; getRequestData(link) { return this.http.get<any>(link).toPromise(); } //assume that this response may // [ // { "id":"1", "name":"Anna" } // { "id":"2", "name":"Martin" } // ] //now let add new propertie country in response object getRequestData(link).then( (resObject) =>{ this.newObject.push( ...resObject.Data.map( (obj)=>({ ...obj , country:"India" }) ); ); }) //now your response in newObject is like // [ // { "id":"1", "name":"Anna","country":"India" } // { "id":"2", "name":"Martin","country":"India" } // ]