我正在angular-timer
为我的项目使用插件,我在其中显示带有任务和持续时间的项目我想一次只运行一个计时器,然后单击其他开始按钮,所有这些都将被禁用,请给我任何想法,我该怎么做在控制器内的angularJs 中找到所有计时器元素。
<tr ng-repeat="project in projects" id="{{project.id}}">
<td>{{project.id}}</td>
<td>{{project.name}}</td>
<td>{{project.task}}</td>
<td>{{project.estimation}}</td>
<td><timer interval="1000">{{hours}} hour{{hoursS}}, {{minutes}} min{{minutesS}}, {{seconds}} sec{{secondsS}}.</timer></td>
<td><input type="text" class="text-center" value="{{project.comment}}"></td>
<td>
<button ng-click="startStopTimer($event,project.id)" ng-disabled="timerRunning" class="btn btn-success">Start</button>
<button ng-click="resumeTimer($event,project.id)" class="btn btn-warning">Pause</button>
<button class="btn btn-danger">Delete</button>
</td>
</tr>
内部 Angular 控制器
$scope.timerRunning = false;
$scope.startStopTimer = function ($event,sectionId) {
console.log($event.currentTarget.innerHTML);
if ($event.currentTarget.innerHTML === 'Start') {
console.log('---------------ssssss-------------');
console.log($scope);
document.getElementById(sectionId).getElementsByTagName('timer')[0].stop();
$event.currentTarget.innerHTML = 'Stop';
$scope.timerRunning = false;
angular.forEach(function(sectionId) {
document.getElementById(sectionId).getElementsByTagName('timer')[0].stop();
});
}
else {
console.log($event);
console.log('---------------resume-------------');
document.getElementById(sectionId).getElementsByTagName('timer')[0].start();
$event.currentTarget.innerHTML = 'Start';
}
};
项目的虚拟数据
$scope.projects = [{
"id": "1",
"name": "Project 1",
"time": "1pm - 2.30 pm",
"comment": "some comment on project",
"estimation": "1.5 hr",
"task": "Working on project task"
}, {
"id": "2",
"name": "Project 2",
"time": "1pm - 2.30 pm",
"comment": "some comment on project",
"estimation": "5 hr",
"task": "Working on project task"
}, {
"id": "3",
"name": "Project 3",
"time": "1pm - 2.30 pm",
"comment": "some comment on project",
"estimation": "6 hr",
"task": "Working on prject task"
}];