vendredi 4 novembre 2016

How to trigger an action using an Ember Service?

I am attempting to use an Ember Service to trigger the same action on multiple routes.

Here is what the service looks like:

import Ember from 'ember';

export default Ember.Service.extend({
  actions: {
    changeBackground() {
      Ember.$('body').toggleClass('bg-color-change');
    }
  }
});

I am then sticking this into the template:

<button id="change-theme" class="btn" >Change Theme</button>

And this into the route handler:

import Ember from 'ember';

export default Ember.Route.extend({
  ...
  changeTheme: Ember.inject.service(),
  ...
});

What am I missing here? I suspect the syntax is wrong in some way, I'm just not really sure where to go from here. Please note that this must be accomplished using an Ember Service, if possible.

Any help would be greatly appreciated!




Aucun commentaire:

Enregistrer un commentaire