[Ionic 4] How do I make a countdown timer with Angular?

How do I Make a Simple Countdown Timer?


I believe there are plenty examples in javascript, which you can use in an angular project. The angular angle will probably give you hassle in change detection if you use one way binding. There you could try a manual update using zone or other manual change update changedetectorref or something…

Or use the viewchild to update the DOM content directly in order to keep up with the changes in time (through the nativeelement). This to have the angular way of finding the DOM element (getElementByID)

My 2 cents

i used this in in one of my project. may be it will help



Very cool!

With css and all that!

1 Like

I want to countdown with date from API service. No content related to this topic.

Cannot use it…dddd

Type ‘number’ is not assignable to type ‘string’.ts(2322)

you can simply write the toString() function to avoid issue.

Its not working, it says:

core.js:4197 ERROR Error: Uncaught (in promise): TypeError: Cannot set property 'textContent' of null
TypeError: Cannot set property 'textContent' of null

As I understand, Your code not able to find that element of id ‘countdown-number’. Are you sure you have this element in your html page? And if possible, can you share you html code?

Thanks i fixed it, but now i would like to know how to execute something when interval finishes, thank you!

I would use RxJS’s interval operator to do this, which provides a very clean segue to your question about how to do something when the countdown finishes, by combining the take and finalize operators.

1 Like