Renderer2
Extend this base class to implement custom rendering. By default, Angular renders a template into DOM. You can use custom rendering to intercept rendering calls, or to render to something other than DOM.
data
{ [key: string]: any; }Use to store arbitrary developer-defined data on a renderer instance, as an object containing key-value pairs. This is useful for renderers that delegate to other renderers.
destroy
voidImplement this callback to destroy the renderer or the host element.
voidcreateElement
anyImplement this callback to create an instance of the host element.
stringAn identifying name for the new element, unique within the namespace.
string | null | undefinedThe namespace for the new element.
anyThe new element.
createComment
anyImplement this callback to add a comment to the DOM of the host element.
stringThe comment text.
anyThe modified element.
createText
anyImplement this callback to add text to the DOM of the host element.
stringThe text string.
anyThe modified element.
destroyNode
((node: any) => void) | nullIf null or undefined, the view engine won't call it. This is used as a performance optimization for production mode.
appendChild
voidAppends a child to a given parent node in the host element DOM.
anyThe parent node.
anyThe new child node.
voidinsertBefore
voidImplement this callback to insert a child node at a given position in a parent node in the host element DOM.
anyThe parent node.
anyThe new child nodes.
anyThe existing child node before which newChild is inserted.
boolean | undefinedOptional argument which signifies if the current insertBefore is a result of a
move. Animation uses this information to trigger move animations. In the past the Animation
would always assume that any insertBefore is a move. This is not strictly true because
with runtime i18n it is possible to invoke insertBefore as a result of i18n and it should
not trigger an animation move.
voidremoveChild
voidImplement this callback to remove a child node from the host element's DOM.
anyThe parent node.
anyThe child node to remove.
boolean | undefinedOptionally signal to the renderer whether this element is a host element
boolean | undefinedOptionally signal to the renderer whether this element needs synchronous removal
voidselectRootElement
anyImplement this callback to prepare an element to be bootstrapped as a root element, and return the element instance.
anyThe DOM element.
boolean | undefinedWhether the contents of the root element
should be preserved, or cleared upon bootstrap (default behavior).
Use with ViewEncapsulation.ShadowDom to allow simple native
content projection via <slot> elements.
anyThe root element.
parentNode
anyImplement this callback to get the parent of a given node in the host element's DOM.
anyThe child node to query.
anyThe parent node, or null if there is no parent. This is because the check is synchronous, and the caller can't rely on checking for null.
nextSibling
anyImplement this callback to get the next sibling node of a given node in the host element's DOM.
anyanyThe sibling node, or null if there is no sibling. This is because the check is synchronous, and the caller can't rely on checking for null.
setAttribute
voidImplement this callback to set an attribute value for an element in the DOM.
anyThe element.
stringThe attribute name.
stringThe new value.
string | null | undefinedThe namespace.
voidremoveAttribute
voidImplement this callback to remove an attribute from an element in the DOM.
anyThe element.
stringThe attribute name.
string | null | undefinedThe namespace.
voidaddClass
voidImplement this callback to add a class to an element in the DOM.
anyThe element.
stringThe class name.
voidremoveClass
voidImplement this callback to remove a class from an element in the DOM.
anyThe element.
stringThe class name.
voidsetStyle
voidImplement this callback to set a CSS style for an element in the DOM.
anyThe element.
stringThe name of the style.
anyThe new value.
voidremoveStyle
voidImplement this callback to remove the value from a CSS style for an element in the DOM.
anyThe element.
stringThe name of the style.
voidsetProperty
voidImplement this callback to set the value of a property of an element in the DOM.
anyThe element.
stringThe property name.
anyThe new value.
voidsetValue
voidImplement this callback to set the value of a node in the host element.
anyThe node.
stringThe new value.
voidlisten
() => voidImplement this callback to start an event listener.
anyThe context in which to listen for events. Can be the entire window or document, the body of the document, or a specific DOM element.
stringThe event to listen for.
(event: any) => boolean | voidA handler function to invoke when the event occurs.
() => voidAn "unlisten" function for disposing of this handler.
Description
Extend this base class to implement custom rendering. By default, Angular renders a template into DOM. You can use custom rendering to intercept rendering calls, or to render to something other than DOM.
Please be aware that usage of `Renderer2`, in context of accessing DOM elements, provides no
extra security which makes it equivalent to
Security vulnerabilities.
Create your custom renderer using RendererFactory2.
Use a custom renderer to bypass Angular's templating and
make custom UI changes that can't be expressed declaratively.
For example if you need to set a property or an attribute whose name is
not statically known, use the setProperty() or
setAttribute() method.