G
G
Ghoulll2020-06-16 14:58:20
Angular
Ghoulll, 2020-06-16 14:58:20

How to access a variable from another component?

The component has a variable that is responsible for the timer (time of user inactivity).

timer: number;
...
  ngAfterViewInit(): void {
    this.timer = 0;
    setInterval( () => {
      this.timer ++;
    }, 1000);
  }

  @HostListener('window:mousemove', ['$event'])
  refreshTimer(e: MouseEvent): any {
    this.timer = 0;
  }


How to access this variable from any other component (for example, to reset filtering after a certain time of inactivity)?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shvets, 2020-06-16
@Ghoulll

You do not need to access the component field, you need to keep this data in the service, and pick it up and display it in the component.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question