Skip to content

Commit

Permalink
[Angular] Signals to handle errorMessage (jhipster#25078)
Browse files Browse the repository at this point in the history
  • Loading branch information
qmonmert authored Feb 4, 2024
1 parent f1f2b32 commit afdf20b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
<div class="col-md-8">
<h1 <%= jhiPrefix %>Translate="error.title">__jhiTransformTranslate__('error.title')</h1>

@if (errorMessage) {
<div class="alert alert-danger">{{ errorMessage }}</div>
@if (errorMessage()) {
<div class="alert alert-danger">{{ errorMessage() }}</div>
}
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
See the License for the specific language governing permissions and
limitations under the License.
-%>
import { Component, inject, OnInit<% if (enableTranslation) { %>, OnDestroy<% } %> } from '@angular/core';
import { Component, inject, signal, OnInit<% if (enableTranslation) { %>, OnDestroy<% } %> } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
<%_ if (enableTranslation) { _%>
import { Subscription } from 'rxjs';
Expand All @@ -31,7 +31,7 @@ import SharedModule from 'app/shared/shared.module';
imports: [SharedModule],
})
export default class ErrorComponent implements OnInit<% if (enableTranslation) { %>, OnDestroy<% } %> {
errorMessage?: string;
errorMessage = signal<string | undefined>(undefined);
<%_ if (enableTranslation) { _%>
errorKey?: string;
langChangeSubscription?: Subscription;
Expand All @@ -50,7 +50,7 @@ export default class ErrorComponent implements OnInit<% if (enableTranslation) {
this.getErrorMessageTranslation();
this.langChangeSubscription = this.translateService.onLangChange.subscribe(() => this.getErrorMessageTranslation());
<%_ } else { _%>
this.errorMessage = routeData.errorMessage;
this.errorMessage.set(routeData.errorMessage);
<%_ } _%>
}
});
Expand All @@ -64,10 +64,10 @@ export default class ErrorComponent implements OnInit<% if (enableTranslation) {
}

private getErrorMessageTranslation(): void {
this.errorMessage = '';
this.errorMessage.set('');
if (this.errorKey) {
this.translateService.get(this.errorKey).subscribe(translatedErrorMessage => {
this.errorMessage = translatedErrorMessage;
this.errorMessage.set(translatedErrorMessage);
});
}
}
Expand Down

0 comments on commit afdf20b

Please sign in to comment.