Javascript ember.js clearInterval不工作

Javascript ember.js clearInterval不工作,javascript,ember.js,setinterval,clearinterval,Javascript,Ember.js,Setinterval,Clearinterval,在ember.js中,clearInterval函数在我调用timerEnd函数时不起作用 解决此代码问题的正确方法是什么。谢谢。尝试添加计时器变量并清除该变量而不是ctimer。(未测试) 输入错误,应该是:this.clearInterval(this.timer);您可能应该使用Thank You@Caqu,它工作得很好!!在TimerEnd功能中删除此项后。 App.Controller = Ember.ObjectController.extend({ timerStart:

在ember.js中,clearInterval函数在我调用timerEnd函数时不起作用


解决此代码问题的正确方法是什么。谢谢。

尝试添加计时器变量并清除该变量而不是ctimer。(未测试)


输入错误,应该是:this.clearInterval(this.timer);您可能应该使用Thank You@Caqu,它工作得很好!!在TimerEnd功能中删除此项后。
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();

       }
});
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();
  },
});