ember js中的Flash消息不起作用。创建Flash对象时对象未定义

时间:2017-01-13 05:51:07

标签: javascript twitter-bootstrap ember.js flash-message ember-cli-rails

组件。

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

组件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!');
        }
    }
});

错误消息:未捕获的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

警告讯息:未定义

因此,服务注入由于某种原因不起作用。我错过了什么 指南我提到:https://github.com/poteto/ember-cli-flash#displaying-flash-messages

ember install ember-bootstrap ember安装ember-cli-flash

安装了这两个。

1 个答案:

答案 0 :(得分:1)

每当我们安装任何ember插件时,都需要停止并启动ember serve

一般情况下,每当我遇到任何问题,我都会搜索相应的项目github问题列表,这将有助于我解决。在这种情况下,我刚刚找到并确认了此issuesolution