【问题标题】:Angular calling function in child component from parent component来自父组件的子组件中的角度调用函数
【发布时间】:2020-05-22 20:59:51
【问题描述】:

从子组件调用父组件中的函数时出现错误。我想我在从父级调用func() 时在子组件中犯了一些错误

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

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

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

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

【问题讨论】:

  • 您能分享一下您遇到的错误是什么吗?

标签: angular


【解决方案1】:

试试这个,

parent.component.html

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

child.component.ts

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-30
    • 2019-02-01
    • 2022-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-27
    相关资源
    最近更新 更多