1

I have been trying out the new Angular 20, I noticed a few test cases were failing, the test cases specifically were using ng-reflect-* to identify elements to test.

Below are two examples and screenshots highlighting my problem.

Angular 19 - ng-reflect-* is present:

enter image description here

Stackblitz Demo

Angular 20 - ng-reflect-* is missing:

Stackblitz Demo

enter image description here

Code:

@Component({
  selector: 'app-child',
  template: `
    {{user().firstName}} | {{user().lastName}}
  `,
})
export class Child {
  user = input.required<any>();
}
@Component({
  selector: 'app-root',
  imports: [Child],
  template: `
    <app-child [user]="user"/>
  `,
})
export class App {
  user: any = {
    firstName: 'test',
    lastName: 'tester',
  };
}
2

2 Answers 2

4

TL;DR

The ng-reflect-* attributes are not produced by default in Angular 20, if you need to use them, kindly add provideNgReflectAttributes to the providers array of bootstrap application.

import { Component, input, provideNgReflectAttributes } from '@angular/core';
import { bootstrapApplication } from '@angular/platform-browser';
...

...
bootstrapApplication(App, {
  providers: [
    provideNgReflectAttributes()
  ],
});

Stackblitz Demo

Note: If you do not seem to have the ng-reflect-* attributes after adding them to the providers array, kindly delete the cache folder (.angular) and restart the server.


As a part of the new Angular 20 Release.

There is a commit and pull request providing the details for this.

refactor(core): stop producing ng-reflect attributes by default #60973

This commit deprecates ng-reflect-* attributes and updates the runtime to stop producing them by default. Please refactor application and test code to avoid relying on ng-reflect-* attributes.

To enable a more seamless upgrade to v20, we've added the provideNgReflectAttributes() function (can be imported from the @angular/core package), which enables the mode in which Angular would be producing those attribites (in dev mode only). You can add the provideNgReflectAttributes() function to the list of providers within the bootstrap call.

In my case I needed these attributes since few test cases were using them as markers to identify elements for testing.

Sign up to request clarification or add additional context in comments.

Comments

0

They are deprecated though (https://angular.dev/api/core/provideNgReflectAttributes), I suggest you use other attributes or selectors like data-cy for Cypress tests

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.