Skip to content

[attr.width.px] can't work in angular9 #36256

Closed

Description

@DreamLi1314

Env

  • os: win10
  • browser: Chrome 80.0.3987.149(x64)
  • package.json
    "@angular/animations": "^9.0.7",
    "@angular/cdk": "^9.1.3",
    "@angular/common": "^9.0.7",
    "@angular/compiler": "^9.0.7",
    "@angular/core": "^9.0.7",
    "@angular/forms": "^9.0.7",
    "@angular/localize": "^9.0.7",
    "@angular/material": "^9.1.3",
    "@angular/material-moment-adapter": "^9.1.3",
    "@angular/platform-browser": "^9.0.7",
    "@angular/platform-browser-dynamic": "^9.0.7",
    "@angular/router": "^9.0.7"

Desc

<td *ngIf="hasContent(r, c)"
    [attr.width.px]="model?.cells[r][c]?.width"
    [attr.height.px]="model?.cells[r][c]?.height + (isEditableMode() && last ? 1 : 0)"

Browser Display

Rendering failed because the property was compiled to width.px

Activity

  1. DreamLi1314 commented on Mar 26, 2020

    @DreamLi1314
    Author

    [style.width.px]="model?.cells[r][c]?.width" and [attr.width]="model?.cells[r][c]?.width" is work for me.
    But I think this should be a mistake or why doesn't this work in Angular9?

  2. pkozlowski-opensource commented on Mar 26, 2020

    @pkozlowski-opensource
    Member

    tl;dr; this is not the valid syntax and it just "happened to work" in previous versions of Angular. As @DreamLi1314 suggested you need to use one of:

    • [style.width.px]="expression" if you want to bind to the CSS style property (probably this is what you want);
    • [att.width]="expression + 'px'" if you want to bind to the width attribute

    What was happening with the VE attribute parser that any suffix would be dropped without any warning ( https://stackblitz.com/edit/angular-9qzvjk) which isn't greatest user experience... I'm going to keep this issue open so we can decide what to do here (probably error when detecting such usage pattern).

  3. added
    area: compilerIssues related to `ngc`, Angular's template compiler
    area: coreIssues related to the framework runtime
    core: binding & interpolationIssue related to property/attribute binding or text interpolation
    on Mar 26, 2020
  4. modified the milestone: needsTriage on Mar 26, 2020
  5. modified the milestones: needsTriage, Backlog on Mar 26, 2020
  6. DreamLi1314 commented on Mar 27, 2020

    @DreamLi1314
    Author

    ok, thanks.

  7. 8 remaining items

  8. self-assigned this
    on Jun 28, 2022
  9. angular-automatic-lock-bot commented on Aug 8, 2022

    @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.

  10. locked and limited conversation to collaborators on Aug 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions