Skip to content

Allow template literal in attribute with string record value #61572

Closed

Description

@g-drouard

Which @angular/* package(s) are relevant/related to the feature request?

compiler

Description

It works :

@let widthPx = `${width}px`;
<div [ngStyle]="{ width: widthPx }"></div>
<div [ngStyle]="{ width: width + 'px' }"></div>

It doesn't work :

<div [ngStyle]="{ width: `${width}px` }"></div>

With this error message : Parser Error: Missing expected } at the end of the expression [{ width: `${width}px` }]

I wrote an angular-eslint rule prefer-template-literal to force writing in template literal but this limitation is very annoying because it applies the wrong fixes.

Proposed solution

<div [ngStyle]="{ width: `${width}px` }"></div>

Alternatives considered

I could try to detect the special case in the lint rule to using @let but that would be really annoying

Activity

  1. modified the milestone: needsTriage on May 21, 2025
  2. added 3 commits that reference this issue on May 22, 2025
    aea2edd
    6f929eb
    19a4d7e
  3. added a commit that references this issue on May 26, 2025
    6ca7590
  4. added a commit that references this issue on May 26, 2025
    24bab55
  5. added a commit that references this issue on May 26, 2025
    3e102f0
  6. angular-automatic-lock-bot commented on Jun 26, 2025

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

  7. locked and limited conversation to collaborators on Jun 26, 2025
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

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions