Call a method of the child component

前端 未结 4 2051
执笔经年
执笔经年 2020-12-07 17:42

I have a nested child component like this:


    

         


        
4条回答
  •  佛祖请我去吃肉
    2020-12-07 18:09

    You can get a reference to an element using

    @ViewChild('childComponent') child;
    

    where childComponent is a template variable >` or

    @ViewChild(ComponentType) child;
    

    where ComponentType is the type of a component or directive and then in ngAfterViewInit or an event handlers call child.someFunc().

    ngAfterViewInit() {
      console.log(this.child);
    }
    

    See also get hold of an element in the template

提交回复
热议问题