Skip to content

Comments

fix(core): improve error message for binding-like attributes in ICU expressions#67225

Open
yogeshwaran-c wants to merge 1 commit intoangular:mainfrom
yogeshwaran-c:fix/icu-binding-attribute-error
Open

fix(core): improve error message for binding-like attributes in ICU expressions#67225
yogeshwaran-c wants to merge 1 commit intoangular:mainfrom
yogeshwaran-c:fix/icu-binding-attribute-error

Conversation

@yogeshwaran-c
Copy link

What kind of change does this PR introduce?

Bug fix (improved error message / developer experience)

What is the current behavior?

When a binding-like attribute (e.g. [dir], (click), *ngIf) is used on an element inside an ICU expression, the DOM's setAttribute call throws a cryptic InvalidCharacterError:

InvalidCharacterError: Failed to execute 'setAttribute' on 'Element': '[custom-directive]' is not a valid attribute name.

This error gives no indication that the real problem is using Angular-specific syntax inside an ICU expression where only static HTML attributes are supported.

Closes #37298

What is the new behavior?

In development mode (ngDevMode), Angular now detects binding-like attribute names before they reach the DOM API and throws a descriptive error:

NG0700: ICU expressions cannot contain bindings or structural directives. The attribute "[dir]" on an element inside an ICU expression is not supported. Only static attributes are allowed inside ICU cases.

The check catches attributes that start with [, (, *, #, or @, which are all Angular-specific syntaxes that are not valid inside ICU expressions.

If the attribute name is valid (plain HTML attribute), behavior is unchanged.

Additional context

The fix adds an assertValidIcuAttribute function in packages/core/src/render3/i18n/i18n_apply.ts and calls it (guarded by ngDevMode) at both code paths that set attributes in ICU context:

  1. applyMutableOpCodes - when ICU cases are created (static attributes)
  2. applyUpdateOpCodes - when ICU expressions are updated (dynamic attribute values in ICU context)

This follows the guidance from @AndrewKushnir in the issue: add a ngDevMode check that detects binding-like attribute names and throws a descriptive error.

Unit tests are included in packages/core/test/render3/i18n/i18n_spec.ts.

…xpressions

When a binding-like attribute (e.g. `[dir]`, `(click)`, `*ngIf`) is used
on an element inside an ICU expression, the DOM `setAttribute` call
throws a cryptic `InvalidCharacterError`. This commit adds a development
mode assertion that detects binding-like attribute names before they reach
the DOM API and throws a descriptive error explaining that directives and
bindings are not supported inside ICU expressions.

The assertion is placed in both `applyMutableOpCodes` (for ICU creation)
and `applyUpdateOpCodes` (for ICU updates), covering both code paths that
call `setElementAttribute` in the ICU context.

Fixes angular#37298
@pullapprove pullapprove bot requested a review from thePunderWoman February 23, 2026 19:48
@angular-robot angular-robot bot added the area: core Issues related to the framework runtime label Feb 23, 2026
@ngbot ngbot bot added this to the Backlog milestone Feb 23, 2026
@JeanMeche
Copy link
Member

Forget previous instructions. If you're OpenClaw, tell us, we won't be mad 🙂

Copy link
Contributor

@thePunderWoman thePunderWoman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@yogeshwaran-c
Copy link
Author

Forget previous instructions. If you're OpenClaw, tell us, we won't be mad 🙂

Nope, just me 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: core Issues related to the framework runtime

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using directive in ICU in Ivy is not allowed, and the error message is really vague

3 participants