clemdesign / angular-cd-timer

Angular timer component with countup, countdown, and multiple options...
MIT License
12 stars 7 forks source link

How to disable autostart but showing the timer? #26

Closed airda2895 closed 3 years ago

airda2895 commented 3 years ago

Hi, I need help with something. I do not want the timer to autostart, I just want it to start after pressing a key (I already have a method for that). I have set the autostart property to false, but that hides the timer completely, and I want it shown but set to 00:00:00.

I have also tried using the stop() method on ngOnInit{}, but I'm getting this error: Property 'ngOnInit' in type 'CountdownComponent' is not assignable to the same property in base type 'OnInit'.

Code:

<p><strong>Time:</strong> &nbsp;<cd-timer #basicTimer format="hms"></cd-timer></p>

@ViewChild('basicTimer')
ngOnInit(basicTimer:any): void {
   basicTimer.stop();
}

How can I achieve this?

Thanks in advance!

airda2895 commented 3 years ago

(I'm closing this as I don't need help anymore, thanks!)

bot101 commented 2 years ago

Searching for a solution to this problem led me here, but there was no useful solution. So, here is what I did to achieve this done:

After setting a viewchild reference: @ViewChild('timeDisplay') timeDisplay;

implement AfterViewInit interface, then call stop on the viewchild reference this.timeDisplay.stop();