I have 2 Javascript functions. The first returns value to the second. In the second function, I am not able to access a constant declared earlier.
I have tried renaming the constant.
//app.service.ts
import { Injectable, OnModuleInit } from '@nestjs/common';
import { Observable, of } from 'rxjs';
@Injectable()
export class AppService implements OnModuleInit {
constant1 = 'constant1';
onModuleInit() {
this.someFunction1()
.pipe(
this.someFunction2,
).subscribe(console.log);
}
private someFunction1(): Observable<string> {
console.log('someFunction1');
console.log('constant1 = ', this.constant1);
return of('done');
}
private someFunction2(something:Observable<string>):Observable<string> {
console.log('someFunction1');
console.log('constant1 = ', this.constant1);
// Cannot read property of constant1
return of('done');
}
}
I expect the output is 'constant1'. But I get an error of 'cannot read property of constant1.'