mardi 14 mars 2017

How to observe the value in Ember

I am trying to make my first Ember application and I am struggling with Ember.set() error.

My nextMonth function is working fine and rendering fine but if I add to my view I get an error.

View:

<h2></h2>
<button >Next</button>




Controller:

import Ember from 'ember';

export default Ember.Controller.extend({

month: new Date().getMonth() + 1,
year: new Date().getFullYear(),

getDays: function(year, month){
  const date = new Date(year, month, 0).getDate();
  this.set('days', date);
},

init: function() {
 this.getDays(this.month, this.year);
},

actions:{
  nextMonth: function(){
    if(this.month !== 12){
      this.set('month', this.month++);
    }
    else if(this.month === 12){
      this.set('month', 1);
      this.set('year', this.year++);
    }
    this.getDays(this.year, this.month);
 }
}
});




Aucun commentaire:

Enregistrer un commentaire