diff --git a/packages/animations/browser/src/render/dom_animation_engine.ts b/packages/animations/browser/src/render/dom_animation_engine.ts index c92deae667..4e6119b55f 100644 --- a/packages/animations/browser/src/render/dom_animation_engine.ts +++ b/packages/animations/browser/src/render/dom_animation_engine.ts @@ -67,11 +67,18 @@ export class DomAnimationEngine { } onInsert(element: any, domFn: () => any): void { - this._flaggedInserts.add(element); + if (element['nodeType'] == 1) { + this._flaggedInserts.add(element); + } domFn(); } onRemove(element: any, domFn: () => any): void { + if (element['nodeType'] != 1) { + domFn(); + return; + } + let lookupRef = this._elementTriggerStates.get(element); if (lookupRef) { const possibleTriggers = Object.keys(lookupRef); diff --git a/packages/animations/browser/src/render/noop_animation_engine.ts b/packages/animations/browser/src/render/noop_animation_engine.ts index 58100c0d2d..42063638ad 100644 --- a/packages/animations/browser/src/render/noop_animation_engine.ts +++ b/packages/animations/browser/src/render/noop_animation_engine.ts @@ -54,7 +54,9 @@ export class NoopAnimationEngine extends AnimationEngine { onRemove(element: any, domFn: () => any): void { domFn(); - this._flaggedRemovals.add(element); + if (element['nodeType'] == 1) { + this._flaggedRemovals.add(element); + } } setProperty(element: any, property: string, value: any): void { diff --git a/packages/animations/browser/test/engine/dom_animation_engine_spec.ts b/packages/animations/browser/test/engine/dom_animation_engine_spec.ts index 365eaa02f5..3d1b749a54 100644 --- a/packages/animations/browser/test/engine/dom_animation_engine_spec.ts +++ b/packages/animations/browser/test/engine/dom_animation_engine_spec.ts @@ -328,6 +328,29 @@ export function main() { }); }); + describe('removals / insertions', () => { + it('should allow text nodes to be removed through the engine', () => { + const engine = makeEngine(); + const node = document.createTextNode('hello'); + element.appendChild(node); + + let called = false; + engine.onRemove(node, () => called = true); + + expect(called).toBeTruthy(); + }); + + it('should allow text nodes to be inserted through the engine', () => { + const engine = makeEngine(); + const node = document.createTextNode('hello'); + + let called = false; + engine.onInsert(node, () => called = true); + + expect(called).toBeTruthy(); + }); + }); + describe('transition operations', () => { it('should persist the styles on the element as actual styles once the animation is complete', () => { diff --git a/packages/platform-browser/animations/test/noop_animation_engine_spec.ts b/packages/platform-browser/animations/test/noop_animation_engine_spec.ts index ef36ba1211..8c6bd9019f 100644 --- a/packages/platform-browser/animations/test/noop_animation_engine_spec.ts +++ b/packages/platform-browser/animations/test/noop_animation_engine_spec.ts @@ -20,8 +20,8 @@ export function main() { () => { const engine = new NoopAnimationEngine(); - const elm1 = {}; - const elm2 = {}; + const elm1 = {nodeType: 1}; + const elm2 = {nodeType: 1}; engine.onRemove(elm1, capture('1')); engine.onRemove(elm2, capture('2')); @@ -158,7 +158,7 @@ export function main() { it('should fire a removal listener even if the listener is deregistered prior to flush', () => { const engine = new NoopAnimationEngine(); - const elm = {}; + const elm = {nodeType: 1}; const fn = engine.listen(elm, 'trig', 'start', capture('removal listener')); fn();