2017-04-19 40 views
0

我有一個EventEmitter,我如下發光的對象:如何發射的物體,其值

@Output() cellClick = new EventEmitter(); 
private _cellClicked(data: any){ 
     let emitData: any = { 
     colId: data.column.colId, 
     rowId: data.node.id, 
     item: {} 
     }; 
     if (emitWithdata){ 
      this.cellClick.next(emitData); // Here i need to send my data also, and it need to append to the value Data.item=data not just the Data object. 
     } 
     if (emitWithNodata){ 
       this.cellClick.next(emitData); // here i just pass the emitData with empty item, which is correct 
     } 


} 

如何通過與emitData數據?任何想法的傢伙?在此先感謝

+2

我不明白這個問題。無論你想發出什麼,只是發出它你的意思是「我的數據」是什麼? *如何使用其值發出一個對象* 對象** IS **的值。 (順便說一句,你不想用'emit'而不是'next'?)。 – 2017-04-19 03:12:38

+0

對不起,我的數據意味着'數據'在函數 – blackdaemon

+0

的參數中傳遞。所以如果我在我的監聽器中發出'emitData',我就有這個對象,但是'item'將是空的。我需要傳遞'_cellClicked'函數的參數'data'作爲參數傳遞給我的父代或監聽器 – blackdaemon

回答

0

要發送數據回事件處理程序,您可以這樣寫: this.cellClick.emit({data:emitData,orderData:someData});

+0

我想要通過兩個單獨的長,任何方式我只能發送emitData,但項目將是數據 – blackdaemon

2

如果我們按照角EventEmitter API: https://angular.io/docs/ts/latest/api/core/index/EventEmitter-class.html

  1. 變化EventEmmiter報關使用:EventEmitter
  2. 要送你必須使用emmit方法的數據。

您的代碼應該是這樣的:

@Output() cellClick: EventEmitter<any> = new EventEmitter(); 
private _cellClicked(data: any){ 
     let emitData: any = { 
     colId: data.column.colId, 
     rowId: data.node.id, 
     item:{} 
     }; 
     if (emitWithdata){ 
      emitData.item=data; 
      this.cellClick.emit(emitData); // Here i need to send my data also, and it need to append to the value Data.item=data not just the Data object. 
     } 
} 
+0

該項目是一個空的對象在聲明。數據將附加在emitwithdata condetion中 – blackdaemon