Angular 2 calling a child component method from the parent

戏子无情 提交于 2019-12-06 06:19:37

Parent html should be like:

<child-component #childComponent></child-component>

then you can access this element with @ViewChild

export class ParentComponent implements OnChanges, OnInit {
    ...

    @ViewChild('childComponent') childComponent;

Right now your @ViewChild('ChildComponent') childComponent; selects nothing since you don't have a #ChildComponent selector in your template.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!