Currently, I am working on a service that is responsible for setting and getting the value of an object. The issue I am facing is that even though I am successfully sending the value to the setter function, when I try to retrieve it later, the values remain unchanged. Can someone please review the code snippet below and help me identify what could be causing this persistence of old values? (Note: I have omitted some component headers and imports for brevity.)
//service.ts
export class NavService {
private location;
constructor(){
this.location = {
next:'',
back: ''
}
}
setLocation(back:string, next:string){
this.location.next = next;
this.location.back = back;
}
getLocation(){
return this.location;
}
}
In my view, there is a button that triggers either the next() or back() functions to update the location.
export class PlanComponent {
location;
currentPage : string = 'start';
constructor(private nav:NavService){}
forward(){
this.location = this.nav.getLocation();
this.currentPage = this.location.next;
}
}
When loading a new location which loads a new component, the new component should set the new location. However, in the parent component, attempting to get the location still provides the same old values.
export class AboutComponent {
constructor(private nav: NavService){
this.nav.setLocation('start', 'about');
}
}
Your time and attention in reviewing this matter are greatly appreciated!