refactor(docs-infra): use input bindings in docs component (#58826)

Use reactive inputs instead of manually getting data from the
currently activated route.

PR Close #58826
This commit is contained in:
Pawel Kozlowski
2024-11-22 18:46:51 +01:00
committed by Jessica Janiuk
parent d2b8a1fc98
commit 2c8cb13bcf
2 changed files with 5 additions and 12 deletions
@@ -1,7 +1,8 @@
@if (documentContent()) {
@let docContent = this.docContent();
@if (docContent) {
<docs-viewer
class="docs-viewer"
[docContent]="documentContent()!.contents"
[docContent]="docContent.contents"
[hasToc]="true"
/>
}
+2 -10
View File
@@ -7,10 +7,7 @@
*/
import {DocContent, DocViewer} from '@angular/docs';
import {ChangeDetectionStrategy, Component, inject} from '@angular/core';
import {toSignal} from '@angular/core/rxjs-interop';
import {ActivatedRoute} from '@angular/router';
import {map} from 'rxjs/operators';
import {ChangeDetectionStrategy, Component, input} from '@angular/core';
@Component({
selector: 'docs-docs',
@@ -21,14 +18,9 @@ import {map} from 'rxjs/operators';
templateUrl: './docs.component.html',
})
export default class DocsComponent {
private readonly activatedRoute = inject(ActivatedRoute);
// Based on current route, proper static content for doc page is fetched.
// In case when exists example-viewer placeholders, then ExampleViewer
// components are going to be rendered.
private readonly documentContent$ = this.activatedRoute.data.pipe(
map((data) => data['docContent'] as DocContent),
);
documentContent = toSignal(this.documentContent$);
docContent = input<DocContent>();
}