lundi 26 octobre 2015

How to toggle class in Ember

I'm trying to figure out how I can toggle a class in a component.

I have my component that has two states: active and desactive. When I want to active it, I need add the class active.

Currently I'm using jQuery addClass and removeClass.

Component.js:

SiteApp.BookingBoxComponent = Ember.Component.extend({
      actions: {
        open: function (element) {
          this.sendAction('open', this.$());
        },

        close: function (element) {
          this.sendAction('close', this.$());
        },
      }
});

Controller.js:

SiteApp.IndexController = Ember.Controller.extend({
  actions: {
    open: function (element) {
      element.addClass('event--active');
    },

    close: function (element) {
      element.removeClass('event--active');
    },
  }
});

It is working, but I have this feeling that Ember has something build in that will help with this.




Aucun commentaire:

Enregistrer un commentaire