首页 > 解决方案 > 访问 DOM 中表示 Angular 组件的对象

问题描述

有没有办法通过某种引用访问 DOM 中表示 Angular 组件的对象并在其上调用方法?

标签: angular

解决方案


尝试

html

<component></component>
<div *ngIf="componentObj"> componentObj.Method() </div>

打字稿

    @ViewChild(component)
    public componentObj: ComponentType;

推荐阅读