MCPcopy Create free account
hub / github.com/angular/angular / DefaultDomRenderer2

Class DefaultDomRenderer2

packages/platform-browser/src/dom/dom_renderer.ts:303–539  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

301}
302
303class DefaultDomRenderer2 implements Renderer2 {
304 data: {[key: string]: any} = Object.create(null);
305
306 /**
307 * By default this renderer throws when encountering synthetic properties
308 * This can be disabled for example by the AsyncAnimationRendererFactory
309 */
310 throwOnSyntheticProps = true;
311
312 constructor(
313 private readonly eventManager: EventManager,
314 private readonly doc: Document,
315 protected readonly ngZone: NgZone,
316 private readonly tracingService: TracingService<TracingSnapshot> | null,
317 private readonly cssVarNamespace: string = '',
318 ) {}
319
320 destroy(): void {}
321
322 destroyNode = null;
323
324 createElement(name: string, namespace?: string): any {
325 if (namespace) {
326 // TODO: `|| namespace` was added in
327 // https://github.com/angular/angular/commit/2b9cc8503d48173492c29f5a271b61126104fbdb to
328 // support how Ivy passed around the namespace URI rather than short name at the time. It did
329 // not, however extend the support to other parts of the system (setAttribute, setAttribute,
330 // and the ServerRenderer). We should decide what exactly the semantics for dealing with
331 // namespaces should be and make it consistent.
332 // Related issues:
333 // https://github.com/angular/angular/issues/44028
334 // https://github.com/angular/angular/issues/44883
335 return this.doc.createElementNS(NAMESPACE_URIS[namespace] || namespace, name);
336 }
337
338 return this.doc.createElement(name);
339 }
340
341 createComment(value: string): any {
342 return this.doc.createComment(value);
343 }
344
345 createText(value: string): any {
346 return this.doc.createTextNode(value);
347 }
348
349 appendChild(parent: any, newChild: any): void {
350 const targetParent = isTemplateNode(parent) ? parent.content : parent;
351 targetParent.appendChild(newChild);
352 }
353
354 insertBefore(parent: any, newChild: any, refChild: any): void {
355 if (parent) {
356 const targetParent = isTemplateNode(parent) ? parent.content : parent;
357 // If something outside Angular removed or moved `refChild` (a browser extension, for
358 // example), the native call below throws a `NotFoundError` with no useful info. Catch it
359 // here so we can say what actually happened.
360 if (refChild != null && refChild.parentNode !== targetParent) {

Callers

nothing calls this directly

Calls 1

createMethod · 0.65

Tested by

no test coverage detected