I have a simple timer in my searchstatusComponent:
import { Component, OnInit, DoCheck, OnDestroy } from '@angular/core';
@Component({
selector: 'app-searchstatus',
templateUrl: './searchstatus.component.html',
styleUrls: ['./searchstatus.component.scss']
})
export class SearchstatusComponent implements OnInit, DoCheck, OnDestroy {
intervalId = 0;
seconds = 0;
minutes = 0;
message = '';
constructor() { }
ngOnInit() {
// this.start();
}
ngDoCheck() {
}
ngOnDestroy() {
this.clearTimer();
}
start() {
this.minutes = 0;
this.seconds = 0;
this.countTime();
console.log('starting');
}
stop() {
this.clearTimer();
}
private countTime() {
this.clearTimer();
this.intervalId = window.setInterval(() => {
this.seconds += 1;
this.message = `${this.minutes} min., ${this.seconds} sec`;
if (this.seconds === 60) {
this.minutes++;
this.seconds = 0;
}
}, 1000);
}
clearTimer() {
clearInterval(this.intervalId);
}
}
and in my SearchstatusComponent.html
<div>Elapsed Time: {{message}}</div>
Now when I trigger start()
from onInit()
everything works fine.. BUT if I trigger start()
from the parent component, the variable in the template simply does not get updated (?)
the method runs, i can see this in the console, the only thing is the display in the template. what am I doing wrong?