我想用角度js编写时间跟踪器。 我旁边HTML代码Angular JS更新ng-repeat
<tr ng-repeat="task in tasks">
<td>1</td>
<td>{{task.name}}</td>
<td class="text-right">{{task.time}}</td>
</tr>
我有模型任务
function Task(name, time) {
this.name = name;
this.time = time;
this.incrementTime = function($scope) {
this.time++;
}
}
所以我想更新任务每秒钟在控制器 像这样
function TaskController($scope, $interval) {
$scope.tasks = [];
$scope.addTask = function() {
var task = new Task($scope.task, 0);
$interval(task.incrementTime, 1000);
$scope.tasks.unshift(task);
$scope.task = '';
}
}
但我的表不更新任务
http://plnkr.co/edit/ ?p = streamer&s = GYw5zvmCIPpQoxHC –
1.您不需要表单和ng-submit,只需使用ng-click即可。 2.你正在使用旧版本的角度,没有$间隔,使用最新版本。 – haimlit
谢谢,它的工作原理 –