角度计时器无法分别启动多个计时器

时间:2017-03-09 14:56:42

标签: javascript angularjs angular-timer

我在ng-repeat中使用uib-tabset,每个标签中都有计时器。每个计时器都有一个“开始”按钮,因此每个计时器都可以在某个动作上启动。

<uib-tabset active="activeTab">
<uib-tab ng-repeat="question in vm.QuestionsList" index="question.Index" disable="question.disabled">
    <uib-tab-heading>
        Q{{question.Index}}
    </uib-tab-heading>

    <timer countdown="question.TimeForQuestionInSeconds" interval="1000" finish-callback="vm.questionTimeOut()" autostart="false" id="q{{question.Index}}-timer">
        Remaining time : {{countdown}} second{{secondsS}} <br />
        <div class="progress progress-striped active {{displayProgressActive}}" style="height: 15px;"><div class="bar" style="width: {{progressBar}}%;"></div> </div>
    </timer>

    <button type="button" class="btn btn-default btn-sm" ng-click="vm.startTimer()" ng-disabled="vm.TimerRunning">Start</button>
</uib-tab>
</uib-tabset>

在我的控制器中我有这个功能:

public startTimer() {
            this.$scope.$broadcast('timer-start');
            this.TimerRunning = true;
        }

但它启动了我的所有计时器。我在这里找到了这个解决方案https://github.com/siddii/angular-timer/issues/166

document.getElementById('q1-timer').start();

但我收到此错误Uncaught TypeError: document.getElementById(...).start is not a function并且不知道原因。还有其他办法吗?

0 个答案:

没有答案