Karthik Saxena
Karthik Saxena

Reputation: 888

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

I have a requirement in which I have to call a parent component function from child. As obvious we can use @Output parameter with EventEmitter to achieve this. But the challenge here is the parent component is something like this

func(param1,param2){
}

I want to call this method from the child so I used something like this.

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

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

It is able to call the function that I have seen but the parameters are not getting passed. Can anyone please suggest what am I doing wrong or missing something?

Upvotes: 4

Views: 2539

Answers (1)

Adrita Sharma
Adrita Sharma

Reputation: 22213

Try like this:

parent.html

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

Working Demo

Upvotes: 9

Related Questions