ryanto / ember-flash-message

Flash message for Ember.JS templates.
49 stars 23 forks source link

How to set class/type when using in controller? #26

Open herrherrmann opened 9 years ago

herrherrmann commented 9 years ago

Hello there,

I want to trigger flash messages from within controllers because that's where my actions lie.
Is there a way to set the class/type of the flashmessage within a controller, too?

I already tried stuff like:

App.PostController = Ember.ObjectController.extend({
  needs: ['flashMessage'],
  actions: {
    // ...
    removePost: function () {
      var confirmed = confirm("Are you sure you want to remove the post \"" + this.get('title') + "\"?");
      if (confirmed) {
        var post = this.get('model');
        post.deleteRecord();
        post.save();
        var flashMessage = this.get('controllers.flashMessage');
        this.transitionTo('posts')
        .then(function() {
          flashMessage.set('message', 'Blog post removed!');
          flashMessage.set('message.type', 'alert alert-success');
        });
      }
    }
  }
});

... but my resulting flashmessage keeps having an empty class attribute.

P.S.: I'm using @treygriffith's version since I'm on ember 1.10.0. P.P.S.: I just noticed that the message text isn't showing either! So both parameters are not being send to the output properly.