I'm making a simple web app for mobile devices that allows you to add timers with names and work types and then count how much time you spent on it. I'm trying to use with start-time attr to show user how much time passed since specific timer started:
<div class="timers list" ng-controller="TimersCtrl">
<ul>
<li ng-repeat="timer in timers">
<span>{{timer.projectName}}</span>
<span>({{timer.workType}})</span>
<timer start-time="timer.start">{{millis | date: "hh:mm:ss"}}</timer>
<span class="stop-timer button" ng-click="stopTimer(timer)">Stop</span>
</li>
</ul>
</div>
And the controller code:
timeboard.controller("TimersCtrl", ["$scope", "$http", "$rootScope", function($scope, $http, $rootScope) {
$scope.updateTimers = function(){
$http({method:"GET", url:"/api/v1/timers"}).success(function(data, status, headers, config) {
$rootScope.timers = data;
});
};
$scope.stopTimer = function(timer){
$http({method:"DELETE", url:("/api/v1/timers/" + timer._id)}).success(function(data, status, headers, config) {
$rootScope.timers = data;
});
};
$scope.updateTimers();
});
This controller only loads timers on page load and allows you to stop the timer
Timers are added from the other controller:
timeboard.controller("ProjectsCtrl", ["$scope", "$http", "$rootScope", "$timeout", function($scope, $http, $rootScope, $timeout) {
// some irrelevant code
$scope.startTimer = function(project){
$http({method:"POST", url: "/api/v1/timers", data: { PID: project._id, PName: project.name, worktype: project.workName } }).success(function(data, status, headers, config) {
project.usage = project.usage + 1;
$scope.updateWorkTypes();
$rootScope.timers = data;
});
};
// some irrelevant code
});
So the problem is that when I add new timer, it doesn't start to count time automatically, and this happens only in Chrome for Mobile (Desktop Chrome and its mobile emulation works fine), when I then refresh page or delete other timer or add a new one (this causes $rootScope timers to update with $http req) this one, that wasn't counting before, starts to count time
I'm sorry if i'm missing something very simple here, but please, let me know, if it isn't supposed to happen
EDIT: and of course let me know if you need some additional info