I have an Angular 2 component where I want to retrieve an element div
<div id ="myId">
by its id. I try doing: document.getElementById("myId")
in my component (TypeScript), but i get an error: "cannot find name document". I see that in other posts we can do something similar using @ViewChild, however I don't see how we can use this with a div, any ideas?
相关问题
- Angular RxJS mergeMap types
- npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fs
- How to update placeholder text in ng2-smart-table?
- How to instantiate Http service in main.ts manuall
- Angular: ngc or tsc?
相关文章
- angular脚手架在ie9+下兼容问题
- angular 前端项目 build 报错 "Cannot find module 'le
- Angular Material Stepper causes mat-formfield to v
- After upgrade to Angular 9 cannot find variable in
- is there any difference between import { Observabl
- Suppress “Circular dependency detected” suppress w
- How can you get current positional information abo
- Angular material table not showing data
Add Template Reference variable to the element you need access to:
And in the component:
You can use @ViewChild with a div by adding a TemplateRef.
Template
Component
This blog post by Kara Erickson is a really good read for getting familiar with the Angular approach to doing things like this.