Change a value of a variable in an angular component from an event listener handler

Viewed 136

I have an event listener and an event handler:

ngOnInit(): void {
    document.addEventListener('focusin', this.lastElementFocused);
}

and the handler function:

lastElementFocused() {
    this.lastActiveElement = document.activeElement;
}

lastActiveElement is created in my component:

export class MyComponent implements OnInit {
  lastActiveElement: Element;
  ...

However, the handler function isn't able to change the value of the variable, when I try to use the variable outside the handler function it doesn't contain the updated value.

Can anyone help?

0 Answers
Related