Upon creating a service to share data among multiple components, it became necessary to reset the object values once the process was complete. To achieve this, I attempted the following: this.UserDetails = {};
This successfully cleared the values and removed any nested objects, effectively resetting the service object to its default state.
Many thanks.
Below is my service file:
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class dataService {
constructor() { }
UserDetails: any = {
key1 : '' ,
key2: {
Status: false,
Label: ''
},
key3: {
Status: false,
Label: ''
},
key4: {
Status: false,
Label: ''
},
key5: '',
key6: '',
key7: new Date(),
}
}
After assigning values in components, the UserDetails object appears as follows:
UserDetails = {
key1 : 'value 1' ,
key2: {
Status: true,
Label: 'label 1'
},
key3: {
Status: false,
Label: 'label 2'
},
key4: {
Status: true,
Label: 'label 3'
},
key5: 'key value 1',
key6: 'key value 2',
key7: new Date(),
}
}
Once the data is passed to the backend, it is necessary to reset to the default values in the service file.