mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
0f86a0b9e7
PR Close #51455
28 lines
918 B
TypeScript
28 lines
918 B
TypeScript
import {Component, Injector} from '@angular/core';
|
|
import {createCustomElement} from '@angular/elements';
|
|
import {PopupComponent} from './popup.component';
|
|
import {PopupService} from './popup.service';
|
|
|
|
@Component({
|
|
standalone: true,
|
|
selector: 'app-root',
|
|
template: `
|
|
<input #input value="Message" />
|
|
<button type="button" (click)="popup.showAsComponent(input.value)">Show as component</button>
|
|
<button type="button" (click)="popup.showAsElement(input.value)">Show as element</button>
|
|
`,
|
|
providers: [PopupService],
|
|
imports: [PopupComponent],
|
|
})
|
|
export class AppComponent {
|
|
constructor(
|
|
injector: Injector,
|
|
public popup: PopupService,
|
|
) {
|
|
// Convert `PopupComponent` to a custom element.
|
|
const PopupElement = createCustomElement(PopupComponent, {injector});
|
|
// Register the custom element with the browser.
|
|
customElements.define('popup-element', PopupElement);
|
|
}
|
|
}
|