Skip to content

Can't initialize Angular Element with a "falsy" element property value #30834

Closed
@antch

Description

@antch

🐞 bug report

Affected Package

The issue is caused by package @angular/elements

Is this a regression?

No.

Description

When using an Angular Element as a custom element, a component @Input cannot be initialized to false (or other falsy value) via setting the element's property value.

🔬 Minimal Reproduction

Stackblitz that shows failure to initialize both "false" (for boolean) and 0 (for number): https://stackblitz.com/edit/angular-elements-test-input-bindings

I debugged this and this if condition appears to be causing it (component-factory-strategy.ts#L168):

if (initialValue) {
    this.setInputValue(propName, initialValue);
} else {
    // Keep track of inputs that were not initialized in case we need to know this for
    // calling ngOnChanges with SimpleChanges
    this.uninitializedInputs.add(propName);
}

This is treating any "falsy" value as uninitialized, which is incorrect.

🔥 Exception or Error

There is no error, the boolean false input value is not set to the component input.

🌍 Your Environment

Angular Version:


Angular CLI: 7.3.9
Node: 10.14.2
OS: darwin x64
Angular: 7.2.15
... animations, common, compiler, compiler-cli, core, elements
... forms, http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.13.9
@angular-devkit/build-angular     0.13.9
@angular-devkit/build-optimizer   0.13.9
@angular-devkit/build-webpack     0.13.9
@angular-devkit/core              7.3.9
@angular-devkit/schematics        7.3.9
@angular/cdk                      7.2.2
@angular/cli                      7.3.9
@ngtools/webpack                  7.3.9
@schematics/angular               7.3.9
@schematics/update                0.13.9
rxjs                              6.4.0
typescript                        3.2.4
webpack                           4.29.0

Activity

changed the title [-]Can't initialize Angular Element with a `false` element property value[/-] [+]Can't initialize Angular Element with a "falsy" element property value[/+] on Jun 3, 2019
added this to the needsTriage milestone on Jun 4, 2019
added a commit that references this issue on Jul 18, 2019
7151eae
added a commit that references this issue on Jul 18, 2019
434b796
added a commit that references this issue on Sep 6, 2019
0849213
angular-automatic-lock-bot

angular-automatic-lock-bot commented on Sep 15, 2019

@angular-automatic-lock-bot

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

locked and limited conversation to collaborators on Sep 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: elementsIssues related to Angular Elements

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      Participants

      @mhevery@antch

      Issue actions

        Can't initialize Angular Element with a "falsy" element property value · Issue #30834 · angular/angular