diff --git a/modules/angular2/src/platform/dom/dom_renderer.ts b/modules/angular2/src/platform/dom/dom_renderer.ts index e44fef1833..b2c2e99c81 100644 --- a/modules/angular2/src/platform/dom/dom_renderer.ts +++ b/modules/angular2/src/platform/dom/dom_renderer.ts @@ -1,7 +1,5 @@ import {Inject, Injectable, OpaqueToken} from 'angular2/src/core/di'; import {AnimationBuilder} from 'angular2/src/animate/animation_builder'; - -import {StringMapWrapper} from 'angular2/src/facade/collection'; import { isPresent, isBlank, @@ -42,9 +40,8 @@ import { DefaultProtoViewRef } from 'angular2/src/core/render/view'; import {ViewEncapsulation} from 'angular2/src/core/metadata'; - -// TODO move it once DdomAdapter is moved import {DOM} from 'angular2/src/platform/dom/dom_adapter'; +import {camelCaseToDashCase} from './util'; const NAMESPACE_URIS = CONST_EXPR({'xlink': 'http://www.w3.org/1999/xlink', 'svg': 'http://www.w3.org/2000/svg'}); @@ -162,11 +159,7 @@ export abstract class DomRenderer extends Renderer implements NodeFactory var existingBindings = RegExpWrapper.firstMatch( TEMPLATE_BINDINGS_EXP, StringWrapper.replaceAll(DOM.getText(element), /\n/g, '')); var parsedBindings = Json.parse(existingBindings[1]); - if (isPresent(propertyValue)) { - parsedBindings[dashCasedPropertyName] = propertyValue; - } else { - StringMapWrapper.delete(parsedBindings, dashCasedPropertyName); - } + parsedBindings[dashCasedPropertyName] = propertyValue; DOM.setText(element, StringWrapper.replace(TEMPLATE_COMMENT_TEXT, '{}', Json.stringify(parsedBindings))); } else { diff --git a/modules/angular2/src/platform/server/parse5_adapter.ts b/modules/angular2/src/platform/server/parse5_adapter.ts index 78d45a47fd..9570c74e74 100644 --- a/modules/angular2/src/platform/server/parse5_adapter.ts +++ b/modules/angular2/src/platform/server/parse5_adapter.ts @@ -239,21 +239,25 @@ export class Parse5DomAdapter extends DomAdapter { treeAdapter.appendChild(el, content.childNodes[i]); } } - getText(el): string { + getText(el, isRecursive?: boolean): string { if (this.isTextNode(el)) { return el.data; + } else if (this.isCommentNode(el)) { + // In the DOM, comments within an element return an empty string for textContent + // However, comment node instances return the comment content for textContent getter + return isRecursive ? '' : el.data; } else if (isBlank(el.childNodes) || el.childNodes.length == 0) { return ""; } else { var textContent = ""; for (var i = 0; i < el.childNodes.length; i++) { - textContent += this.getText(el.childNodes[i]); + textContent += this.getText(el.childNodes[i], true); } return textContent; } } setText(el, value: string) { - if (this.isTextNode(el)) { + if (this.isTextNode(el) || this.isCommentNode(el)) { el.data = value; } else { this.clearNodes(el); diff --git a/modules/angular2/test/core/linker/integration_spec.ts b/modules/angular2/test/core/linker/integration_spec.ts index 39abca7307..92c3545c8c 100644 --- a/modules/angular2/test/core/linker/integration_spec.ts +++ b/modules/angular2/test/core/linker/integration_spec.ts @@ -1613,7 +1613,7 @@ export function main() { it('should reflect property values on template comments', inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => { - var tpl = ''; + var tpl = ''; tcb.overrideView(MyComp, new ViewMetadata({template: tpl, directives: [NgIf]})) .createAsync(MyComp) diff --git a/modules/angular2/test/web_workers/worker/renderer_integration_spec.ts b/modules/angular2/test/web_workers/worker/renderer_integration_spec.ts index 199bc1a430..dbeca90582 100644 --- a/modules/angular2/test/web_workers/worker/renderer_integration_spec.ts +++ b/modules/angular2/test/web_workers/worker/renderer_integration_spec.ts @@ -189,7 +189,7 @@ export function main() { it('should update any template comment property/attributes', inject([TestComponentBuilder, Renderer, AsyncTestCompleter], (tcb: TestComponentBuilder, renderer: Renderer, async) => { - var tpl = ''; + var tpl = ''; tcb.overrideView(MyComp, new ViewMetadata({template: tpl, directives: [NgIf]})) .createAsync(MyComp)