Skip to content

Commit

Permalink
Merge pull request #10368 from qmonmert/angularsignalapp
Browse files Browse the repository at this point in the history
Angular: uses Signal
  • Loading branch information
pascalgrimaud authored Jul 23, 2024
2 parents 92b26b0 + ce484c5 commit a6472b1
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class AngularOauth2ModuleFactory {
import { Oauth2AuthService } from './auth/oauth2-auth.service';
""";

private static final ElementReplacer APPNAME_NEEDLE = lineAfterRegex("appName = '';");
private static final ElementReplacer APPNAME_NEEDLE = lineAfterRegex("appName = signal\\(''\\);");

private static final String INJECT_OAUTH2_AUTH_SERVICE =
"""
Expand All @@ -87,10 +87,10 @@ public class AngularOauth2ModuleFactory {

private static final String INJECT_IMPORT =
"""
import { Component, inject, OnInit } from '@angular/core';
import { Component, inject, OnInit, signal } from '@angular/core';
""";

private static final ElementReplacer INJECT_NEEDLE = text("import { Component, OnInit } from '@angular/core';");
private static final ElementReplacer INJECT_NEEDLE = text("import { Component, OnInit, signal } from '@angular/core';");

private static final ElementReplacer BEFORE_EACH_NEEDLE = lineAfterRegex("comp = fixture.componentInstance;");

Expand Down Expand Up @@ -173,7 +173,7 @@ public JHipsterModule buildModule(JHipsterModuleProperties properties) {
.add(fileStart(), LOGIN_IMPORT)
.add(INJECT_NEEDLE, INJECT_IMPORT)
.add(APPNAME_NEEDLE, INJECT_OAUTH2_AUTH_SERVICE)
.add(lineAfterRegex("this.appName = '" + properties.projectBaseName().name() + "';"), INIT_AUTHENTICATION)
.add(lineAfterRegex("this.appName.set\\('" + properties.projectBaseName().name() + "'\\);"), INIT_AUTHENTICATION)
.and()
.in(path("src/main/webapp/app/app.component.spec.ts"))
.add(fileStart(), TEST_IMPORTS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<mat-menu #menu="matMenu">
<!-- jhipster-needle-angular-menu -->
</mat-menu>
<span>{{ appName }}</span>
<span>{{ appName() }}</span>
<span class="toolbar-spacer"></span>
<img alt="Angular logo" class="angular-logo" ngSrc="content/images/AngularLogo.svg" width="50" height="50" priority />
<span class="space-separator" id="menu-space-separator"></span>
Expand All @@ -23,7 +23,7 @@
<router-outlet></router-outlet>

<div id="footer">
<h1>{{ appName }}: Angular + TypeScript</h1>
<h1>{{ appName() }}: Angular + TypeScript</h1>
<p>
Recommended IDE setup:
<a href="https://code.visualstudio.com/" target="_blank" rel="noopener">VSCode</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('App Component', () => {
fixture.detectChanges();
// THEN
expect(comp.appName).toEqual('{{baseName}}');
expect(comp.appName()).toEqual('{{baseName}}');
});
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnInit } from '@angular/core';
import { Component, OnInit, signal } from '@angular/core';
import { CommonModule, NgOptimizedImage } from '@angular/common';
import { RouterModule } from '@angular/router';

Expand All @@ -15,9 +15,9 @@ import { MatMenuModule } from '@angular/material/menu';
styleUrl: './app.component.css',
})
export class AppComponent implements OnInit {
appName = '';
appName = signal('');
ngOnInit(): void {
this.appName = '{{baseName}}';
this.appName.set('{{baseName}}');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void shouldCreateAngularModule() {
)
.and()
.hasFile("src/main/webapp/app/app.component.ts")
.containing("this.appName = 'jhiTest'")
.containing("this.appName.set('jhiTest')")
.and()
.hasPrefixedFiles(
"",
Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/projects/angular/app.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('App Component', () => {
fixture.detectChanges();

// THEN
expect(comp.appName).toEqual('test');
expect(comp.appName()).toEqual('test');
});
});
});
6 changes: 3 additions & 3 deletions src/test/resources/projects/angular/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnInit } from '@angular/core';
import { Component, OnInit, signal } from '@angular/core';
import { CommonModule, NgOptimizedImage } from '@angular/common';
import { RouterModule } from '@angular/router';

Expand All @@ -15,9 +15,9 @@ import { MatMenuModule } from '@angular/material/menu';
styleUrl: './app.component.css',
})
export class AppComponent implements OnInit {
appName = '';
appName = signal('');

ngOnInit(): void {
this.appName = 'jhipster';
this.appName.set('jhipster');
}
}

0 comments on commit a6472b1

Please sign in to comment.