1

Component.

{{#each flashMessages.queue as |flash|}}
  {{flash-message flash=flash messageStyle='bootstrap'}}
{{/each}}
<button {{action 'getFlash'}}> Click for Flash </button>

component js

import Ember from 'ember';

export default Ember.Component.extend({
    flashMessages: Ember.inject.service(),
    actions:{
        getFlash(){
            alert(this.get('flashMessages'))
            const flashMessages = Ember.get(this, 'flashMessages');
            flashMessages.success('Success!');
        }
    }
});

Error Message: Uncaught TypeError:

Cannot read property 'success' of undefined
    at Class.getFlash (flash-item.js:8)
    at Class.send (ember.debug.js:39876)
    at Class.superWrapper [as send] (ember.debug.js:39636)
    at ember.debug.js:11124
    at Object.flaggedInstrument (ember.debug.js:17747)
    at ember.debug.js:11123
    at Backburner.run (ember.debug.js:720)
    at Object.run (ember.debug.js:21514)
    at ActionState.handler (ember.debug.js:11103)
    at HTMLButtonElement.<anonymous> (ember.debug.js:41005)
getFlash @ flash-item.js:8
send @ ember.debug.js:39876
superWrapper @ ember.debug.js:39636
(anonymous) @ ember.debug.js:11124
flaggedInstrument @ ember.debug.js:17747
(anonymous) @ ember.debug.js:11123
run @ ember.debug.js:720
run @ ember.debug.js:21514
handler @ ember.debug.js:11103
(anonymous) @ ember.debug.js:41005
dispatch @ jquery.js:5201
elemData.handle @ jquery.js:5009

Alert message: Undefined

So the service injection is not working for some reason. What am I missing. Guide I referred to: https://github.com/poteto/ember-cli-flash#displaying-flash-messages

ember install ember-bootstrap ember install ember-cli-flash

These two were installed.

VC.One
  • 14,790
  • 4
  • 25
  • 57
Flyn Sequeira
  • 718
  • 2
  • 9
  • 25

1 Answers1

1

Whenever we install any ember addon, then it's required to stop and start ember serve.

Generally, Whenever I am facing any issues then I will search in corresponding project github issues list, that will help me to resolve. In this case I just found and confirmed this issue and solution

Ember Freak
  • 12,918
  • 4
  • 24
  • 54