Skip to content

angular: convert ngOnInit to signals#32447

Draft
mshima wants to merge 1 commit intojhipster:mainfrom
mshima:signals
Draft

angular: convert ngOnInit to signals#32447
mshima wants to merge 1 commit intojhipster:mainfrom
mshima:signals

Conversation

@mshima
Copy link
Member

@mshima mshima commented Feb 25, 2026


Please make sure the below checklist is followed for Pull Requests.

When you are still working on the PR, consider converting it to Draft (below reviewers) and adding skip-ci label, you can still see CI build result at your branch.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR modernizes the Angular entity list component by converting from traditional lifecycle hooks (ngOnInit) to signal-based reactive patterns. The changes align with Angular's modern reactive programming model, using signals and effects instead of manual subscription management.

Changes:

  • Replaced ngOnInit lifecycle hook with signal-based effect() functions in the constructor
  • Converted route parameter and filter observables to signals using toSignal()
  • Removed manual subscription management (no more ngOnDestroy needed)

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/list/_entityFile_.ts.ejs Converted component from ngOnInit pattern to signal-based effects; added toSignal for route state and filter changes; removed OnInit interface and manual subscription
generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/list/_entityFile_.spec.ts.ejs Updated test to use component's isLoading property; added test for request cancellation behavior
Comments suppressed due to low confidence (2)

generators/angular/templates/src/main/webapp/app/entities/entityFolder/list/entityFile.ts.ejs:173

  • The toSignal call for filterChanges should include an initialValue option or use requireSync: true to ensure it always has a value. Without this, the effect at line 209 could receive undefined on its first run if the filterChanges observable doesn't emit immediately. Alternatively, add a null check before using the value: const filterOptions = this.filterChanges(); if (filterOptions) { ... }
    protected readonly filterChanges = toSignal(this.filters.filterChanges);

generators/angular/templates/src/main/webapp/app/entities/entityFolder/list/entityFile.ts.ejs:38

  • The Subscription, Observable, and finalize imports are no longer used after converting from ngOnInit to signal-based effects. These imports should be removed from the rxjs import statement to keep the code clean and avoid unused imports.
import { combineLatest<%_ if (!readOnly) { _%>, filter<%_ } _%>, finalize, Observable, Subscription, map, tap } from 'rxjs';

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mshima mshima force-pushed the signals branch 3 times, most recently from 7470d35 to f3a626c Compare February 25, 2026 16:33
@mshima mshima marked this pull request as draft February 27, 2026 15:08
Comment on lines +212 to +216
// if (this.<%= entityInstancePlural %>().length === 0) {
<%_ } _%>
this.load();
<%_ if (paginationNo && searchEngineNo && !jpaMetamodelFiltering) { _%>
// }
Copy link
Member

Choose a reason for hiding this comment

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

Sonar complains about the commented code:

Suggested change
// if (this.<%= entityInstancePlural %>().length === 0) {
<%_ } _%>
this.load();
<%_ if (paginationNo && searchEngineNo && !jpaMetamodelFiltering) { _%>
// }
<%_ } _%>
this.load();
<%_ if (paginationNo && searchEngineNo && !jpaMetamodelFiltering) { _%>

@mshima
Copy link
Member Author

mshima commented Mar 3, 2026

I don’t know why the microfrontends failures, I may revisit this PR in the future.
I will keep open for reference.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants