I am still new to Ionic and especially Angular. I want to update a textview with a number going from 10 to 0 and update each second.
In my class I got a property public timeLeft: string = 'Your timer';
which is bound to the html with <div>{{timeLeft}}</div>
I have tried using regular JavaScript setInterval()
but it fails when I'm trying to update the property timeLeft
using the keyword this
because this
is not in the same scope as the class when running the setInterval function.
I've read that I should use the Angular function $interval
because it has access to the same scope or view, didn't quite understand that part fully.
I found some pieces of code saying I should make a controller and it should contain something along the lines of myApp.controller(function($scope, $interval) {...})
On the Ionic blog I found a post mentioning that some Angular 1 concepts as controllers and scope is out.
So my question is. How do I use Angular $interval to update a textview at an interval in Ionic? A full code example would be fantastic as I'm literally lost here.
- cli-utils: 1.9.2
- Ionic CLI: 3.9.2
- Cordova CLI: 6.5.0
- ionic app-scripts: 2.1.3
- Ionic Framework: ionic-angular 3.6.0