From 21593420386257667519f9036852ccb79603e314 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matias=20Niemel=C3=A4?= Date: Tue, 15 Aug 2017 12:51:29 -0700 Subject: [PATCH] feat(animations): allow @.disabled property to work without an expression (#18713) PR Close #18713 --- .../src/template_parser/binding_parser.ts | 2 +- .../animation/animation_integration_spec.ts | 37 +++++++++++++++++++ .../animations/src/animation_renderer.ts | 3 +- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/packages/compiler/src/template_parser/binding_parser.ts b/packages/compiler/src/template_parser/binding_parser.ts index 1d57173d55..ba1dc77cb1 100644 --- a/packages/compiler/src/template_parser/binding_parser.ts +++ b/packages/compiler/src/template_parser/binding_parser.ts @@ -218,7 +218,7 @@ export class BindingParser { // This will occur when a @trigger is not paired with an expression. // For animations it is valid to not have an expression since */void // states will be applied by angular when the element is attached/detached - const ast = this._parseBinding(expression || 'null', false, sourceSpan); + const ast = this._parseBinding(expression || 'undefined', false, sourceSpan); targetMatchableAttrs.push([name, ast.source !]); targetProps.push(new BoundProperty(name, ast, BoundPropertyType.ANIMATION, sourceSpan)); } diff --git a/packages/core/test/animation/animation_integration_spec.ts b/packages/core/test/animation/animation_integration_spec.ts index e7e5ee5186..e280c70d00 100644 --- a/packages/core/test/animation/animation_integration_spec.ts +++ b/packages/core/test/animation/animation_integration_spec.ts @@ -2691,6 +2691,43 @@ export function main() { fixture.detectChanges(); expect(getLog().length).toEqual(1); }); + + it('should treat the property as true when the expression is missing', () => { + @Component({ + selector: 'parent-cmp', + animations: [ + trigger( + 'myAnimation', + [ + transition( + '* => go', + [ + style({opacity: 0}), + animate(500, style({opacity: 1})), + ]), + ]), + ], + template: ` +
+
+
+ ` + }) + class Cmp { + exp = ''; + } + + TestBed.configureTestingModule({declarations: [Cmp]}); + + const fixture = TestBed.createComponent(Cmp); + const cmp = fixture.componentInstance; + fixture.detectChanges(); + resetLog(); + + cmp.exp = 'go'; + fixture.detectChanges(); + expect(getLog().length).toEqual(0); + }); }); }); diff --git a/packages/platform-browser/animations/src/animation_renderer.ts b/packages/platform-browser/animations/src/animation_renderer.ts index a1addaf351..9c360da927 100644 --- a/packages/platform-browser/animations/src/animation_renderer.ts +++ b/packages/platform-browser/animations/src/animation_renderer.ts @@ -206,7 +206,8 @@ export class AnimationRenderer extends BaseAnimationRenderer implements Renderer setProperty(el: any, name: string, value: any): void { if (name.charAt(0) == ANIMATION_PREFIX) { if (name.charAt(1) == '.' && name == DISABLE_ANIMATIONS_FLAG) { - this.disableAnimations(el, !!value); + value = value === undefined ? true : !!value; + this.disableAnimations(el, value as boolean); } else { this.engine.process(this.namespaceId, el, name.substr(1), value); }