So, I have been trying access my services inside a promise callback. I have added all necessary modules and imported them into my file. I have also declared them in the constructor.
//This is part of my login Component Class and this line code is bound to a //button click
clicked(){
this.http.get(..)toPromise().then( this.loginCallbackHandler ).catch((error) => console.log(error));
//any service accessed here works fine example
console.log(this.app)// this is fine here
}
//
loginCallbackHandler(reponse){
//accessing any service from here produces the the error below (error1)
//For example
console.log(this.html)
//Or
console.log(this.app)
}
//constructor definition
constructor(@Host() public app: AppComponent,
private oauthService: OAuthService,
private http: HttpClient
){}
//Error1
ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'html' of undefined
TypeError: Cannot read property 'html' of undefined
at push../src/app/login/login.page.ts.LoginPage.loginCallbackHandler (login.page.ts:64)
at
Edit: The issue turned out to be an issue in my understanding to the context of the 'this' keyword, but not in angular services.