I have a function called myFunction()
that accepts one argument. My goal is to save this argument to a variable and be able to access it later.
Here is what I am attempting to do:
When a user performs an action, an event is passed as an argument to the myFunction
. Inside myFunction
, I am assigning the event to a variable called saveArg1
.
In component x, I am making a change that should trigger a call to myFunction
in component 1
. This function call is made using subject
.
However, the issue arises when calling myFunction
as saveArg1
is undefined.
So, how can I store an event for later use without relying on localStorage?
**Component 1**
public saveArg1: any;
ngOnInit(){
this.myService.isChanged.subscribe((result) => {
if (result) {
this.myFunction(this.saveArg1);
}
});
}
myFunction(arg1) {
this.saveArg1 = arg1;
....
}
**Component x**
onWeekChange($event) {
this.myService.isChanged.next(true);
}