angular-timer
angular-timer copied to clipboard
Unable to use timer in Ionic code.
I am trying to use timer with my ionic code. Unable to do it. Below is how I am trying to do. Can you please help?
{{item.userName}}
{{item.userContact}}
{{mminutes}} minute{{minutesS}}, {{sseconds}} second{{secondsS}}
{{countdown}}
If you want autostart, remove it. Here is the code. if ($scope.autoStart === undefined || $scope.autoStart === true) { $scope.start();
in index.html:
<script src="bower_components/angular-timer/dist/angular-timer.js"></script>
<script src="bower_components/moment/min/moment.min.js"></script>
<script src="bower_components/moment/min/locales.min.js"></script>
<script src="bower_components/humanize-duration/humanize-duration.js"></script>
In apps.js angular.module('app', ['ionic', 'app.controllers', 'app.routes', 'app.services', 'app.directives', 'timer'])
In the controller I had to user $rootScope.$broadcast or getElementByTagName. I haven't had time to investigate, but I think either 'timer' directive is a sibling to the controller or parent but not a child if invoked as shown.
$rootScope.startTimer = function() {
$rootScope.$broadcast('timer-start');
//document.getElementsByTagName('timer')[0].start();
$scope.timerRunning = true;
};
$scope.stopTimer = function() {
$scope.$broadcast('timer-stop');
document.getElementsByTagName('timer')[0].stop();
in index.html
<!--<script src="bower_components/angular-timer/app/js/_timer.js"></script>-->
<script src="bower_components/angular-timer/dist/angular-timer.js"></script>
<script src="bower_components/moment/min/moment.min.js"></script>
<script src="bower_components/moment/min/locales.min.js"></script>
<script src="bower_components/humanize-duration/humanize-duration.js"></script>