diff --git a/packages/core/src/render3/instructions.ts b/packages/core/src/render3/instructions.ts index f6fad80f48..e195770c05 100644 --- a/packages/core/src/render3/instructions.ts +++ b/packages/core/src/render3/instructions.ts @@ -556,22 +556,38 @@ function getRenderFlags(view: LView): RenderFlags { ////////////////////////// //// Namespace ////////////////////////// -let _currentNS: string|null = null; +let _currentNamespace: string|null = null; -export function setNS(namespace: string) { - _currentNS = namespace; +/** + * Sets the namespace URI that will be used to create elements in {@link element} + * and {@link elementStart} + * @param uri the full namespaceUri + */ +export function namespace(uri: string | null) { + _currentNamespace = uri; } -export function setHtmlNS() { - _currentNS = null; +/** + * Sets the current namespace URI to null, meaning createElement (not createElementNS) + * will be used to create elements in {@link element} and {@link elementStart} + */ +export function namespaceHTML() { + _currentNamespace = null; } -export function setSvgNS() { - _currentNS = 'http://www.w3.org/2000/svg'; +/** + * Sets the current namespace URI to http://www.w3.org/2000/svg, which will be + * used in conjunction with createElementNS in {@link element} and {@link elementStart} + */ +export function namespaceSVG() { + _currentNamespace = 'http://www.w3.org/2000/svg'; } - -export function setMathML() { - _currentNS = 'http://www.w3.org/1998/Math/MathML'; +/** + * Sets the current namespace URI to http://www.w3.org/1998/Math/MathML, which will be + * used in conjunction with createElementNS in {@link element} and {@link elementStart} + */ +export function namespaceMathML() { + _currentNamespace = 'http://www.w3.org/1998/Math/MathML'; } @@ -599,9 +615,9 @@ export function elementStart( ngDevMode && ngDevMode.rendererCreateElement++; - const native: RElement = _currentNS === null || isProceduralRenderer(renderer) ? + const native: RElement = _currentNamespace === null || isProceduralRenderer(renderer) ? renderer.createElement(name) : - (renderer as ObjectOrientedRenderer3).createElementNS(_currentNS, name); + (renderer as ObjectOrientedRenderer3).createElementNS(_currentNamespace, name); ngDevMode && assertDataInRange(index - 1); diff --git a/packages/core/test/bundling/todo/bundle.golden_symbols.json b/packages/core/test/bundling/todo/bundle.golden_symbols.json index 2b63963bd6..8a2c2c97c0 100644 --- a/packages/core/test/bundling/todo/bundle.golden_symbols.json +++ b/packages/core/test/bundling/todo/bundle.golden_symbols.json @@ -177,7 +177,7 @@ "name": "_currentInjector" }, { - "name": "_currentNS" + "name": "_currentNamespace" }, { "name": "_devMode" diff --git a/packages/core/test/render3/instructions_spec.ts b/packages/core/test/render3/instructions_spec.ts index b7e79be99d..32aa8fe6fc 100644 --- a/packages/core/test/render3/instructions_spec.ts +++ b/packages/core/test/render3/instructions_spec.ts @@ -10,7 +10,7 @@ import {NgForOfContext} from '@angular/common'; import {RenderFlags, directiveInject} from '../../src/render3'; import {defineComponent} from '../../src/render3/definition'; -import {bind, container, element, elementAttribute, elementClass, elementEnd, elementProperty, elementStart, elementStyle, elementStyleNamed, interpolation1, renderTemplate, setHtmlNS, setSvgNS, text, textBinding} from '../../src/render3/instructions'; +import {bind, container, element, elementAttribute, elementClass, elementEnd, elementProperty, elementStart, elementStyle, elementStyleNamed, interpolation1, namespaceHTML, namespaceSVG, renderTemplate, text, textBinding} from '../../src/render3/instructions'; import {AttributeMarker, LElementNode, LNode} from '../../src/render3/interfaces/node'; import {RElement, domRendererFactory3} from '../../src/render3/interfaces/renderer'; import {TrustedString, bypassSanitizationTrustHtml, bypassSanitizationTrustResourceUrl, bypassSanitizationTrustScript, bypassSanitizationTrustStyle, bypassSanitizationTrustUrl, sanitizeHtml, sanitizeResourceUrl, sanitizeScript, sanitizeStyle, sanitizeUrl} from '../../src/sanitization/sanitization'; @@ -433,7 +433,7 @@ describe('instructions', () => { it('should render SVG', () => { const t = new TemplateFixture(() => { elementStart(0, 'div', ['id', 'container']); - setSvgNS(); + namespaceSVG(); elementStart(1, 'svg', [ // id="display" 'id', @@ -452,7 +452,7 @@ describe('instructions', () => { ]); element(2, 'circle', ['cx', '200', 'cy', '150', 'fill', '#0000ff']); elementEnd(); - setHtmlNS(); + namespaceHTML(); elementEnd(); });