question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add extended diagnostic to warn when an attribute is not interpreted as a binding

See original GitHub issue

Which @angular/* package(s) are the source of the bug?

core

Is this a regression?

No

Description

Angular does not properly bind an attribute when using attr.foo syntax if there is no interpolation present in the value.

For example, this does not work:

<div attr.foo="bar"></div> <!-- erroneously keeps the attribute as "attr.foo" -->

This DOES work:

<div attr.foo="{{myProp}}"></div>

This also works:

<div [attr.foo]="'bar'"></div>

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/angular-ivy-ybks1w?file=src%2Fapp%2Fapp.component.html,src%2Fapp%2Fapp.module.ts

Please provide the exception or error you saw

The attribute is not set properly on the element using `attr.foo` syntax when no interpolation is present.

Please provide the environment you discovered this bug in (run ng version)

The reproduction link is using Angular 13, but I also encountered this in my project which produces the following output for `ng version`:


Angular CLI: 12.2.16
Node: 14.19.3
Package Manager: npm 6.14.17
OS: darwin x64

Angular: 12.2.16
... animations, cli, common, compiler, compiler-cli, core
... elements, forms, language-service, localize
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1202.16
@angular-devkit/build-angular   12.2.16
@angular-devkit/core            12.2.16
@angular-devkit/schematics      12.2.16
@angular/cdk                    12.2.13
@schematics/angular             12.2.16
ng-packagr                      12.2.7
rxjs                            6.6.3
typescript                      4.3.5
webpack                         5.50.0


### Anything else?

I encountered this in my project previously on Angular 11 as well.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
pkozlowski-opensourcecommented, May 26, 2022

@atscott yeh, I didn’t close this one as I can totally see how it could be confusing. For a user it is not at all clear why attr.x="{{exp}}" sets x attribute and attr.x="static" sets attr.x. In a sense the left-hand side of the assignment (target) changes based on the rhs and I would consider this surprising. So it “works as designed” but probably not “as expected”.

As an alternative to warning we could just set the x attribute for the attr.x="static" case.

0reactions
angular-automatic-lock-bot[bot]commented, Jul 31, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Extended Diagnostics - Angular
Extended diagnostics are warnings by default and do not block compilation. Each diagnostic can be configured as either: warning (default) - The compiler...
Read more >
Diagnostic flags in Clang — Clang 16.0.0git documentation
This diagnostic flag exists for GCC compatibility, and has no effect in Clang. -Waix-compat¶. This diagnostic is enabled by default. Diagnostic text: warning: ......
Read more >
Bindings for Durable Functions - Azure | Microsoft Learn
The Durable Functions extension introduces three trigger bindings that control the execution of orchestrator, entity, and activity functions ...
Read more >
Error and Warning Options (The GNU Fortran Compiler)
Error and Warning Options (The GNU Fortran Compiler) ... Warnings are diagnostic messages that report constructions which are not ... -Wc-binding-type. Warn ......
Read more >
XSL Transformations (XSLT) Version 3.0 - W3C
3.1 XSLT Namespace; 3.2 Extension Attributes; 3.3 XSLT Media Type ... may produce warning messages if the constraint is not satisfied, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found