6
6
* found in the LICENSE file at https://angular.dev/license
7
7
*/
8
8
9
- import { Component , inject } from '@angular/core' ;
9
+ import { Component , computed , inject , signal } from '@angular/core' ;
10
10
import { Router } from '@angular/router' ;
11
11
import { MatIcon } from '@angular/material/icon' ;
12
12
@@ -18,7 +18,7 @@ import {MatIcon} from '@angular/material/icon';
18
18
selector : 'header-link' ,
19
19
template : `
20
20
<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 ()">
22
22
<mat-icon>link</mat-icon>
23
23
</a>
24
24
` ,
@@ -29,18 +29,12 @@ export class HeaderLink {
29
29
* Id of the anchor element. Note that is uses "example" because we instantiate the
30
30
* header link components through the ComponentPortal.
31
31
*/
32
- example : string = '' ;
32
+ readonly example = signal ( '' ) ;
33
33
34
34
/** Base URL that is used to build an absolute fragment URL. */
35
- private _baseUrl : string ;
35
+ private _baseUrl = inject ( Router ) . url . split ( '#' ) [ 0 ] ;
36
36
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
+ } ) ;
46
40
}
0 commit comments