角度$间隔只发射一次?

时间:2015-06-25 15:37:50

标签: javascript angularjs

看哪,我的代码!

我想将每次刻度的elapsedTime增加100,但它似乎只会触发一次。我不太清楚这一点。它会发射一次,但不会重复。

var gravity = angular.module('gravity', []);

    function GravCtrl($interval) {
      this.acceleration = 9.8;
      this.elapsedTime = 0;
      this.speed = 0;
      this.$interval = $interval;
    }

    GravCtrl.prototype.start = function() {
      this.counter = this.$interval(function(that) { 
        that.elapsedTime += 100;
        that.speed = ( that.elapsedTime / 1000.0 ) * that.acceleration;
        console.log('thing firing');
      }(this), 100)
    };

    gravity.controller('GravCtrl', GravCtrl);

0 个答案:

没有答案