/
githubmirror
/
components
Обзор
Документация
Войти
/
githubmirror
/
components
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/dev-app/example/example.ts
85 строк
2 KB
Kristiyan Kostadinov
build: remove explicit OnPush from dev app
18 май 2026, 10:44
18 май 2026, 10:44
40d7c5a
Код
Авторство
О чём код?
/** * @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 { ChangeDetectorRef, Component, Injector, Input, OnInit, ViewContainerRef, inject, } from '@angular/core'; import {BooleanInput, coerceBooleanProperty} from '@angular/cdk/coercion'; import {EXAMPLE_COMPONENTS} from '@angular/components-examples'; import {loadExample} from '@angular/components-examples/private'; @Component({ selector: 'material-example', template: ` @if (showLabel) { <div class="label"> <span class="title"> {{title}} </span> <span class="id"> <{{id}}> </span> </div> } @if (!id) { <div> Could not find example {{id}} </div> } `, styles: ` .label { display: flex; justify-content: space-between; align-items: flex-end; margin: 16px 0; } .title { font-size: 20px; font-weight: 500; } .id { font-size: 13px; font-family: monospace; color: #666; white-space: pre; } `, }) export class Example implements OnInit { private _injector = inject(Injector); private _viewContainerRef = inject(ViewContainerRef); private _changeDetectorRef = inject(ChangeDetectorRef); /** ID of the material example to display. */ @Input() id!: string; @Input() get showLabel(): boolean { return this._showLabel; } set showLabel(v: BooleanInput) { this._showLabel = coerceBooleanProperty(v); } _showLabel = false; title!: string; async ngOnInit() { this.title = EXAMPLE_COMPONENTS[this.id].title; const example = await loadExample(this.id, this._injector); this._viewContainerRef.createComponent(example.component, {injector: example.injector}); this._changeDetectorRef.markForCheck(); } }