Вопрос

App.Controller = Ember.ObjectController.extend({
    timerStart: function () {


        this.timer = setInterval(this.ctimer, 1000);


    },


    timerEnd: function () {

        this.clearInterval(this.ctimer);

    },

    ctimer: function () {

        var d = new Date();
        document.getElementById("timeBar").innerHTML = d.toLocaleTimeString();

       }
});

in ember.js, the clearInterval function not working as I call the timerEnd function.

what is right way to fix the problem on this code. Thank you.

Это было полезно?

Решение

Try adding the timer variable and clearing that one instead of the ctimer. (Not tested)

App.Controller = Ember.ObjectController.extend({  
  timer: null,
  timerStart: function () {
      this.timer = setInterval(this.ctimer, 1000);
  },
  timerEnd: function () {
      this.clearInterval(this.timer);
  },
  ctimer: function () {
      var d = new Date();
      document.getElementById("timeBar").innerHTML = d.toLocaleTimeString();
  },
});
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top