Skip to content

Commit

Permalink
[Angular] Migrate to signals (translate.directive.ts) (jhipster#28196)
Browse files Browse the repository at this point in the history
  • Loading branch information
qmonmert authored Dec 15, 2024
1 parent d729991 commit c0a81fe
Showing 1 changed file with 5 additions and 5 deletions.
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 { inject, Input, Directive, ElementRef, OnChanges, OnInit, OnDestroy } from '@angular/core';
import { inject, input, Directive, ElementRef, OnChanges, OnInit, OnDestroy } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
Expand All @@ -30,8 +30,8 @@ import { translationNotFoundMessage } from 'app/config/translation.config';
selector: '[<%= jhiPrefix %>Translate]',
})
export default class TranslateDirective implements OnChanges, OnInit, OnDestroy {
@Input() <%= jhiPrefix %>Translate!: string;
@Input() translateValues?: Record<string, unknown>;
readonly <%= jhiPrefix %>Translate = input.required<string>();
readonly translateValues = input<Record<string, unknown>>();

private readonly directiveDestroyed = new Subject();

Expand All @@ -58,13 +58,13 @@ export default class TranslateDirective implements OnChanges, OnInit, OnDestroy

private getTranslation(): void {
this.translateService
.get(this.<%= jhiPrefix %>Translate, this.translateValues)
.get(this.<%= jhiPrefix %>Translate(), this.translateValues())
.pipe(takeUntil(this.directiveDestroyed))
.subscribe({
next: value => {
this.el.nativeElement.innerHTML = value;
},
error: () => `${translationNotFoundMessage}[${this.<%= jhiPrefix %>Translate}]`
error: () => `${translationNotFoundMessage}[${this.<%= jhiPrefix %>Translate()}]`
});
}
}

0 comments on commit c0a81fe

Please sign in to comment.