angular/adev/src/app/main.component.ts
SkyZeroZx 22270492f5 docs(docs-infra): Add OnPush change detection for components (#64570)
Improves Angular's OnPush change detection strategy for main and search history components

PR Close #64570
2025-10-22 14:34:26 +00:00

33 lines
990 B
TypeScript

/*!
* @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 {ChangeDetectionStrategy, Component, effect, inject, model} from '@angular/core';
import {IS_SEARCH_DIALOG_OPEN, Search} from '@angular/docs';
import {RouterOutlet} from '@angular/router';
@Component({
selector: 'adev-main',
imports: [RouterOutlet],
template: `<router-outlet />`,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export default class MainComponent {
private readonly displaySearchDialog = inject(IS_SEARCH_DIALOG_OPEN);
private readonly searchService = inject(Search);
readonly search = model<string | undefined>('');
constructor() {
effect(() => {
const search = this.search();
if (search !== undefined) {
this.displaySearchDialog.set(true);
this.searchService.searchQuery.set(search);
}
});
}
}