I have a situation where i need to push the response of an API called to an array. Previously, I hard coded the data like this.
filterrole = [
{ text: 'Supervisor', value: 'Supervisor' },
{ text: 'Administrator', value: 'Administrator'},
{ text: 'Maintainer', value: 'Maintainer' }
];
But now, i need to get the data from the backend. The backend query is fine. this is how the result looks like from the backend called.
["Supervisor","Maintainer","Observer","Administrator"]
the filterrole has it own class which consist of text and value variable.
Role.class
export class Role {
text: string;
value: string;
}
My question is, how do I push the response from the API call into the filterrole variable ? Below is my workaroud.
export class AddGroupComponent implements OnInit {
filterrole: Role [];
ngOnInit() {
this.getDistinctRole();
}
getDistinctRole(): void {
this._dashboardservice.getDistinctRole().subscribe(
resp => {
// what should i do here to push the data into
// filterdata.text and filterdata.value
},
err => {
this.loading = false;
this._nzMessage.create('error', `Error occurred: ${err.message}`);
}
);
}