![](/img/trans.png)
[英]Getting error in Passing multiple data from parent to child component in Angular
[英]getting error while passing data from child component to parent component
我正在開發Angular 7應用程序。 我正在嘗試將數據從子組件發送到父組件,因為我正在將@Output裝飾器與EventEmitter一起使用。
@Output() token:EventEmitter<any> = new EventEmitter<any>();
我收到錯誤消息:
src / app / header / header.component.ts(96,6)中的錯誤:錯誤TS2322:類型'string'無法分配給類型'EventEmitter'。
在這里,我試圖傳遞價值:
token == eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJVc2VySWQiOiI1MmYzZWEyMC0yMDQzLTQ5MjQtODg3Ny0yNTAzZTZkOTZmNTEiLCJleHAiOjE1ODE2NzQ4OTcsImlzcyI6Ik1hZ2ljTWluZCIsImF1ZCI6Ik1hZ2ljTWluZCJ9.DMcMPgM0B2hZRR-qSIQyIG9SDt_q_G9WON3ZtRXX78I
@Output() token: EventEmitter<string> = new EventEmitter<string>(); Initialize :
this.token.emit(tokenValue); // emit the value to the parent
並且,在父.HTML中,您需要捕獲事件:
<child (token)="tokenEvent($event)"></child>
僅當您發出該值時,父級才會接收令牌事件
this.token.emit(tokenValue);
並且,在父級上,您需要執行以下操作:
<child (token)="handleToken($event)"></child>
使用示例: https : //angular.io/api/core/EventEmitter#usage-notes
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.