簡體   English   中英

如何將兩個參數從子組件 angular 7 傳遞給父組件函數?

[英]How to pass two arguments to a parent component function from child component angular 7?

我有一個要求,我必須從子組件調用父組件函數。 很明顯,我們可以使用@Output參數和EventEmitter來實現這一點。 但這里的挑戰是父組件是這樣的

func(param1,param2){
}

我想從孩子那里調用這個方法,所以我使用了這樣的方法。

@Output() childToParent = new EventEmitter<object>();

callParentMethod(){
this.childToParent.emit({param1:this.param1,param2:this.param2});
}

它能夠調用我見過的函數,但沒有傳遞參數。 誰能建議我做錯了什么或遺漏了什么?

像這樣嘗試:

父.html

<child  (childToParent)="func($event.param1, $event.param2)"></child>

工作演示

暫無
暫無

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

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