I have an observable which returns a value that I need to manipulate in a function, so I thought it would be cleaner if I just sent the function as a callback instead of creating a new anonymous function. However I made the change and I started getting this error message: Error: Cannot set properties of undefined (setting 'name')
.
ngOnInit(): void {
this.updateName('First New Name!');
of('Second New Name!')
.pipe(delay(1500))
// .subscribe(name => this.updateName(name)); // Works!
.subscribe(this.updateName); // Doesn't work - Error: Cannot set properties of undefined (setting 'name')
}
updateName(name: string): void {
this.name = name;
}
Is it supposed to work this way? Why is this happening?