Angular 如何使用ViewChild获取HTML元素?
如何使用ViewChild获取整个HTML元素 我试过:Angular 如何使用ViewChild获取HTML元素?,angular,angular8,Angular,Angular8,如何使用ViewChild获取整个HTML元素 我试过: @ViewChild("mapContainer", { static: false }) mapContainer: HTMLElement; 其中“d”为参考: <div #mapContainer></div> 将ElementRef与ViewChild一起使用 import { ElementRef, ViewChild } from '@angular/core'; @ViewChild('m
@ViewChild("mapContainer", { static: false }) mapContainer: HTMLElement;
其中“d”为参考:
<div #mapContainer></div>
将
ElementRef
与ViewChild
一起使用
import { ElementRef, ViewChild } from '@angular/core';
@ViewChild('mapContainer', {static: false})
private el: ElementRef;
ngOnInit(){
const element = this.el.nativeElement;
}
像这样试试
@ViewChild('mapContainer',{static:true})map:ElementRef;
恩戈尼尼特(){
console.log(this.map.nativeElement);
}
您可以阅读有关ViewChild的更多信息。我想使用d作为HTMLElement类型