Cookies concent notice

This site uses cookies from Google to deliver its services and to analyze traffic.
Learn more
Skip to main content
This site is no longer updated.Head to Angular.devHome
/

This is the archived documentation for Angular v17. Please visit angular.dev to see this page for the current version of Angular.

ElementRef

A wrapper around a native element inside of a View.

See more...

Security risk

Permitting direct access to the DOM can make your application more vulnerable to XSS attacks. Carefully review any use of ElementRef in your code. For more detail, see the Security Guide.

      
      class ElementRef<T = any> {
  constructor(nativeElement: T)
  nativeElement: T
}
    

Description

An ElementRef is backed by a render-specific element. In the browser, this is usually a DOM element.

Constructor

      
      constructor(nativeElement: T)
    
Parameters
nativeElement T

Properties

Property Description
nativeElement: T
Use with caution

Use this API as the last resort when direct access to DOM is needed. Use templating and data-binding provided by Angular instead. Alternatively you can take a look at Renderer2 which provides an API that can be safely used.