Let me provide you with a practical example of code that you can implement in your own project:
Example
// Defining global variables to store values
users: any = null;
posts: any = null;
// Sample data for demonstration purposes
data: any[] = [
{users: ['user1', 'user2', 'user3']},
{posts: ['post1', 'post2', 'post3']}
];
getCrudService() {
// Iterating through each object in the array
this.data.forEach(obj => {
// Extracting keys and processing them
Object.keys(obj).forEach(key => {
// Setting values in global variables based on key names
this[String(key)] = obj[String(key)]
})
})
}
Application to your code
this.crudService.get('user.php?mode=test').subscribe((data:any) => {
data.forEach(obj => {
Object.keys(obj).forEach(key => {
this[String(key)] = obj[String(key)]
});
});
});
I trust that this example will assist you in integrating the functionality into your code effectively. If you require further assistance, don't hesitate to reach out.