/
githubmirror
/
angular
Обзор
Документация
Войти
/
githubmirror
/
angular
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
adev/src/app/core/services/header.service.ts
40 строк
1 KB
Matthieu Riegler
docs(docs-infra): Use `@Service` instead of `@Injectable`
23 апр 2026, 21:21
23 апр 2026, 21:21
7414352
Код
Авторство
О чём код?
/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.dev/license */ import {DOCUMENT} from '@angular/common'; import {inject, Service} from '@angular/core'; const ANGULAR_DEV = 'https://angular.dev'; /** * Information about the deployment of this application. */ @Service() export class HeaderService { private readonly document = inject(DOCUMENT); /** * Sets the canonical link in the header. * It supposes the header link is already present in the index.html * * The function behave invariably and will always point to angular.dev, * no matter if it's a specific version build */ setCanonical(absolutePath: string): void { const pathWithoutFragment = this.normalizePath(absolutePath).split('#')[0]; const fullPath = `${ANGULAR_DEV}/${pathWithoutFragment}`; this.document.querySelector('link[rel=canonical]')?.setAttribute('href', fullPath); } private normalizePath(path: string): string { if (path[0] === '/') { return path.substring(1); } return path; } }