[attr.width.px] can't work in angular9
See original GitHub issueEnv
- 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)"
Rendering failed because the property was compiled to width.px
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:6 (2 by maintainers)
Top Results From Across the Web
How to bind a property to style.width in pixels? - Stack Overflow
Press F12 or hit ctrl + shift + i to open Inspect. Go to Elements Tab and find you div and check it's...
Read more >NgStyle - Angular
An attribute directive that updates styles for the containing HTML element. Sets one or more style properties, specified as colon-separated key-value pairs.
Read more >CSS values and units - Learn web development | MDN
The first box has a width set in pixels. As an absolute unit, this width will remain the same no matter what else...
Read more >HTML video width Attribute - W3Schools
The width attribute specifies the width of a video player, in pixels. Tip: Always specify both the height and width attributes for videos....
Read more >Set a inline dynamic css width attribute with angular expression
Hi All, I have come across a handy directive to allow inline style if the angular condition is true. This will fix any...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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 attributeWhat 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).
[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?