如何从 child 组件 angular 7 向 parent 组件函数传递两个参数?
How to pass two arguments to a parent component function from child component angular 7?
我有一个要求,我必须从 child 调用 parent 组件函数。很明显,我们可以使用 @Output
参数和 EventEmitter
来实现这一点。但这里的挑战是 parent 组件是这样的
func(param1,param2){
}
我想从 child 调用这个方法,所以我使用了类似的方法。
@Output() childToParent = new EventEmitter<object>();
callParentMethod(){
this.childToParent.emit({param1:this.param1,param2:this.param2});
}
它能够调用我看到的函数,但参数没有被传递。
任何人都可以建议我做错了什么或遗漏了什么吗?
这样试试:
parent.html
<child (childToParent)="func($event.param1, $event.param2)"></child>
我有一个要求,我必须从 child 调用 parent 组件函数。很明显,我们可以使用 @Output
参数和 EventEmitter
来实现这一点。但这里的挑战是 parent 组件是这样的
func(param1,param2){
}
我想从 child 调用这个方法,所以我使用了类似的方法。
@Output() childToParent = new EventEmitter<object>();
callParentMethod(){
this.childToParent.emit({param1:this.param1,param2:this.param2});
}
它能够调用我看到的函数,但参数没有被传递。 任何人都可以建议我做错了什么或遗漏了什么吗?
这样试试:
parent.html
<child (childToParent)="func($event.param1, $event.param2)"></child>