diff --git a/projects/cdk/services/id.service.ts b/projects/cdk/services/id.service.ts index 0fa8c23a50f1..f5d434a5e8e8 100644 --- a/projects/cdk/services/id.service.ts +++ b/projects/cdk/services/id.service.ts @@ -1,10 +1,5 @@ -import {Injectable} from '@angular/core'; +import {inject, Injectable} from '@angular/core'; -const TUI = 'tui_'; - -/** - * Generates unique ids - */ @Injectable({ providedIn: 'root', }) @@ -12,6 +7,10 @@ export class TuiIdService { private static autoId = 0; public generate(): string { - return `${TUI}${TuiIdService.autoId++}${Date.now()}`; + return `tui_${TuiIdService.autoId++}${Date.now()}`; } } + +export function tuiInjectId(): string { + return inject(TuiIdService).generate(); +} diff --git a/projects/legacy/components/primitive-textfield/textfield/textfield.component.ts b/projects/legacy/components/primitive-textfield/textfield/textfield.component.ts index 83346979adb2..8357f2697434 100644 --- a/projects/legacy/components/primitive-textfield/textfield/textfield.component.ts +++ b/projects/legacy/components/primitive-textfield/textfield/textfield.component.ts @@ -1,5 +1,5 @@ import {ChangeDetectionStrategy, Component, inject} from '@angular/core'; -import {TuiIdService} from '@taiga-ui/cdk/services'; +import {tuiInjectId} from '@taiga-ui/cdk/services'; import {tuiInjectElement} from '@taiga-ui/cdk/utils/dom'; import { TEXTFIELD_CONTROLLER_PROVIDER, @@ -27,8 +27,8 @@ import {TUI_TEXTFIELD_HOST} from '@taiga-ui/legacy/tokens'; }, }) export class TuiTextfieldComponent { + private readonly autoId = tuiInjectId(); private readonly el = tuiInjectElement(); - private readonly idService = inject(TuiIdService); protected readonly controller = inject(TUI_TEXTFIELD_WATCHED_CONTROLLER); protected readonly host = inject(TUI_TEXTFIELD_HOST); @@ -37,7 +37,7 @@ export class TuiTextfieldComponent { } protected get id(): string { - return this.el.id || this.idService.generate(); + return this.el.id || this.autoId; } protected get inputMode(): string {