簡體   English   中英

ember js 中的 Flash 消息不起作用。 創建 Flash 對象時未定義對象

[英]Flash messages in ember js not working. Object undefined when creating a flash object

成分。

{{#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

余燼安裝余燼引導程序余燼安裝余燼cli-flash

安裝了這兩個。

每當我們安裝任何 ember 插件時,都需要停止和啟動ember serve

通常,每當我遇到任何問題時,我都會在相應的項目 github 問題列表中搜索,這將幫助我解決。 在這種情況下,我剛剛發現並確認了這個問題解決方案

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM