Skip to content

Commit 74ee582

Browse files
committed
refactor(docs-example): perf tweaks
1 parent edccdd1 commit 74ee582

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

src/components/docs-example/docs-example.component.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
1-
import { Component, Input } from '@angular/core';
1+
import {
2+
AfterContentInit,
3+
AfterViewInit,
4+
ChangeDetectionStrategy,
5+
ChangeDetectorRef,
6+
Component,
7+
Input
8+
} from '@angular/core';
29

310
import packageJson from '../../../package.json';
411

512
@Component({
613
selector: 'app-docs-example',
714
templateUrl: './docs-example.component.html',
8-
styleUrls: ['./docs-example.component.scss']
15+
styleUrls: ['./docs-example.component.scss'],
16+
changeDetection: ChangeDetectionStrategy.OnPush
917
})
10-
export class DocsExampleComponent {
18+
export class DocsExampleComponent implements AfterContentInit, AfterViewInit {
1119

12-
@Input() fragment?: string;
20+
constructor(
21+
private changeDetectorRef: ChangeDetectorRef
22+
) {}
1323

14-
constructor() { }
24+
@Input() fragment?: string;
1525

1626
private _href = 'https://coreui.io/angular/docs/';
1727

@@ -27,4 +37,12 @@ export class DocsExampleComponent {
2737
const path: string = version ? `${version}/${value}` : '';
2838
this._href = `${docsUrl}${path}`;
2939
}
40+
41+
ngAfterContentInit(): void {
42+
this.changeDetectorRef.detectChanges();
43+
}
44+
45+
ngAfterViewInit(): void {
46+
this.changeDetectorRef.markForCheck();
47+
}
3048
}

0 commit comments

Comments
 (0)