简体   繁体   English

来自父组件的子组件中的角度调用函数

[英]Angular calling function in child component from parent component

I am getting error while calling function in parent component from child component.从子组件调用父组件中的函数时出错。 I think I am doing some mistake in child component while calling func() from parent我想我在从父组件调用func()时在子组件中犯了一些错误

   parent component
    func(){...........}

    parent.html
    <child   (func)="func()"></child>

    child.component.ts
    @Output func = new EventEmitter();

someOtherFunc(){
    this.func.emit();
}

Try this,尝试这个,

parent.component.html父组件.html

<child   (func)="func($event)"></child>

child.component.ts子组件.ts

@Output() func: EventEmitter<any> = new EventEmitter();
someOtherFunc(){
    this.func.emit(null);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM