文章目录 ViewChild ViewChildren ViewChild 第一种:获取DOM <div #box>一个盒子</div> import { AfterViewInit,ViewChild,ElementRef} from '@angular/core'; // static默认false,是否需要提前拿到,静态的和没ngif的可以设置为true @ViewChild('box',{ static:true}) private boxel:ElementRef; ngAfterViewInit(): void{ // 拿到DOM console