Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
DreamLi1314 opened this issue Mar 26, 2020 · 6 comments
Closed

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

DreamLi1314 opened this issue Mar 26, 2020 · 6 comments
Assignees
Labels
area: compiler Issues related to `ngc`, Angular's template compiler area: core Issues related to the framework runtime core: binding & interpolation Issue related to property/attribute binding or text interpolation freq1: low hotlist: error messages P4 A relatively minor issue that is not relevant to core functions state: confirmed type: bug/fix
Milestone

Comments

@DreamLi1314
Copy link

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

@DreamLi1314
Copy link
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?

@pkozlowski-opensource
Copy link
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).

@pkozlowski-opensource pkozlowski-opensource added area: compiler Issues related to `ngc`, Angular's template compiler area: core Issues related to the framework runtime core: binding & interpolation Issue related to property/attribute binding or text interpolation labels Mar 26, 2020
@ngbot ngbot bot modified the milestone: needsTriage Mar 26, 2020
@ngbot ngbot bot modified the milestones: needsTriage, Backlog Mar 26, 2020
@DreamLi1314
Copy link
Author

ok, thanks.

@pkozlowski-opensource
Copy link
Member

Thinking about it a bit more, I would say that, as the very minimum, we should have compile-time error when encountering [attr.width.px] syntax (that is, we should verify that the attribute binding syntax comes only in the [attr.attrname] flavour and is not accepting suffix.

@jelbourn jelbourn added P4 A relatively minor issue that is not relevant to core functions and removed severity1: confusing labels Oct 1, 2020
@vikassrivastava18
Copy link

vikassrivastava18 commented Feb 27, 2021

Not working in Angular 11

[style.width.px]="expression"

@atscott atscott self-assigned this Jun 28, 2022
atscott added a commit to atscott/angular that referenced this issue Jun 30, 2022
…ings

This commit adds an extended diagnostic which warns when style suffixes such as '.px'
are used with attribute bindings (attr.width.px).

Fixes angular#36256
atscott added a commit to atscott/angular that referenced this issue Jun 30, 2022
…ings

This commit adds an extended diagnostic which warns when style suffixes such as '.px'
are used with attribute bindings (attr.width.px).

Fixes angular#36256
atscott added a commit to atscott/angular that referenced this issue Jun 30, 2022
…ings

This commit adds an extended diagnostic which warns when style suffixes such as '.px'
are used with attribute bindings (attr.width.px).

Fixes angular#36256
atscott added a commit to atscott/angular that referenced this issue Jun 30, 2022
…ings

This commit adds an extended diagnostic which warns when style suffixes such as '.px'
are used with attribute bindings (attr.width.px).

Fixes angular#36256
atscott added a commit to atscott/angular that referenced this issue Jun 30, 2022
…ings

This commit adds an extended diagnostic which warns when style suffixes such as '.px'
are used with attribute bindings (attr.width.px).

Fixes angular#36256
atscott added a commit to atscott/angular that referenced this issue Jun 30, 2022
…ings

This commit adds an extended diagnostic which warns when style suffixes such as '.px'
are used with attribute bindings (attr.width.px).

Fixes angular#36256
atscott added a commit to atscott/angular that referenced this issue Jun 30, 2022
…ings

This commit adds an extended diagnostic which warns when style suffixes such as '.px'
are used with attribute bindings (attr.width.px).

Fixes angular#36256
atscott added a commit to atscott/angular that referenced this issue Jun 30, 2022
…ings

This commit adds an extended diagnostic which warns when style suffixes such as '.px'
are used with attribute bindings (attr.width.px).

Fixes angular#36256
atscott added a commit to atscott/angular that referenced this issue Jul 6, 2022
…ings

This commit adds an extended diagnostic which warns when style suffixes such as '.px'
are used with attribute bindings (attr.width.px).

Fixes angular#36256
atscott added a commit to atscott/angular that referenced this issue Jul 8, 2022
…ings

This commit adds an extended diagnostic which warns when style suffixes such as '.px'
are used with attribute bindings (attr.width.px).

Fixes angular#36256
@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Aug 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: compiler Issues related to `ngc`, Angular's template compiler area: core Issues related to the framework runtime core: binding & interpolation Issue related to property/attribute binding or text interpolation freq1: low hotlist: error messages P4 A relatively minor issue that is not relevant to core functions state: confirmed type: bug/fix
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants