【发布时间】:2017-01-13 05:51:07
【问题描述】:
组件。
{{#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!');
}
}
});
错误信息:未捕获类型错误:
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 安装 ember-bootstrap ember 安装 ember-cli-flash
这两个已安装。
【问题讨论】:
-
您是否尝试在安装后停止和启动 ember 服务器?
-
就是这样。谢谢。
标签: javascript twitter-bootstrap ember.js flash-message ember-cli-rails