据我所知,JavaScript中使用了document.getElementById('first')。我想知道是否有其他方法可以访问特定的div,在Angular-8的Typescript中使用它的id。请让我知道,这将是非常有帮助的。
发布于 2019-12-25 21:19:04
您可以使用 @ViewChild() 在typescript.中引用模板元素
模板中的:
<div #MyDiv>Hello World</div>Component.ts中的:
@ViewChild("MyDiv") div: ElementRef;
changeContent() {
this.div.nativeElement.innerHTML = "text";
}https://stackoverflow.com/questions/59478748
复制相似问题