I keep running into issues with OnInit accessing functions within the same component class.
My basic setup is as follows:
import {Component, OnInit} from '@angular/core';
...
export class AppComponent implements OnInit {
login(){...}
ngOnInit() {
this.login(); //1
document.onkeypress = function(e){
if ( document.body === document.activeElement ) {
this.login(); //2
}
};
1 will fire the login function on page load as expected, but 2 complains login isn't a function. How do I appropriately access the login function within AppComponent?
document.onkeypress = (e)=> { ... }- to preserve the lexical scoping ofthis