66 * found in the LICENSE file at https://angular.dev/license
77 */
88
9- import { Component , inject } from '@angular/core' ;
9+ import { Component , computed , inject , signal } from '@angular/core' ;
1010import { Router } from '@angular/router' ;
1111import { MatIcon } from '@angular/material/icon' ;
1212
@@ -18,7 +18,7 @@ import {MatIcon} from '@angular/material/icon';
1818 selector : 'header-link' ,
1919 template : `
2020 <a aria-label="Link to this heading" class="docs-markdown-a"
21- [attr.aria-describedby]="example" [href]="_getFragmentUrl ()">
21+ [attr.aria-describedby]="example() " [href]="_fragmentUrl ()">
2222 <mat-icon>link</mat-icon>
2323 </a>
2424 ` ,
@@ -29,18 +29,12 @@ export class HeaderLink {
2929 * Id of the anchor element. Note that is uses "example" because we instantiate the
3030 * header link components through the ComponentPortal.
3131 */
32- example : string = '' ;
32+ readonly example = signal ( '' ) ;
3333
3434 /** Base URL that is used to build an absolute fragment URL. */
35- private _baseUrl : string ;
35+ private _baseUrl = inject ( Router ) . url . split ( '#' ) [ 0 ] ;
3636
37- constructor ( ) {
38- const router = inject ( Router ) ;
39-
40- this . _baseUrl = router . url . split ( '#' ) [ 0 ] ;
41- }
42-
43- _getFragmentUrl ( ) : string {
44- return `${ this . _baseUrl } #${ this . example } ` ;
45- }
37+ protected readonly _fragmentUrl = computed ( ( ) => {
38+ return `${ this . _baseUrl } #${ this . example ( ) } ` ;
39+ } ) ;
4640}
0 commit comments