2016-09-23 50 views
0

我正在使用Ionic 2創建應用程序。我有一個事件:Ionic2/Angular2事件數據

import {Events} from 'ionic-angular';

發佈

let data = { 
    topic: 'foo' 
}; 
this.events.publish('messages:notify', data); 

訂閱

 this.events.subscribe('messages:notify', (data) => { 
     alert(data.topic); 
     }); 

我希望它提醒'foo',但它提醒'undefined'

任何幫助將不勝感激。

由於

回答

1

data作爲數組被傳遞,所以下面的工作:

this.events.subscribe('messages:notify', (data) => { 
    alert(data[0].topic); 
    });