/** * @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 { Component, effect, Injectable, Injector, input, NgModule, TemplateRef, viewChild, ViewContainerRef, } from '@angular/core'; import {BrowserModule} from '@angular/platform-browser'; // #docregion SimpleExample @Component({ selector: 'hello-world', template: 'Hello World!', standalone: false, }) export class HelloWorld {} @Component({ selector: 'ng-component-outlet-simple-example', template: ``, standalone: false, }) export class NgComponentOutletSimpleExample { // This field is necessary to expose HelloWorld to the template. HelloWorld = HelloWorld; } // #enddocregion // #docregion CompleteExample @Injectable() export class Greeter { suffix = '!'; } @Component({ selector: 'complete-component', template: `{{ label() }}: {{ greeter.suffix }}`, standalone: false, }) export class CompleteComponent { label = input.required(); constructor(public greeter: Greeter) {} } @Component({ selector: 'ng-component-outlet-complete-example', template: ` Ahoj Svet `, standalone: false, }) export class NgComponentOutletCompleteExample { // This field is necessary to expose CompleteComponent to the template. CompleteComponent = CompleteComponent; myInputs = {'label': 'Complete'}; myInjector: Injector; ahojTemplateRef = viewChild.required>('ahoj'); svetTemplateRef = viewChild.required>('svet'); myContent?: any[][]; constructor( injector: Injector, private vcr: ViewContainerRef, ) { this.myInjector = Injector.create({ providers: [{provide: Greeter, deps: []}], parent: injector, }); effect(() => { this.myContent = [ this.vcr.createEmbeddedView(this.ahojTemplateRef()).rootNodes, this.vcr.createEmbeddedView(this.svetTemplateRef()).rootNodes, ]; }); } } // #enddocregion @Component({ selector: 'example-app', template: `
`, standalone: false, }) export class AppComponent {} @NgModule({ imports: [BrowserModule], declarations: [ AppComponent, NgComponentOutletSimpleExample, NgComponentOutletCompleteExample, HelloWorld, CompleteComponent, ], }) export class AppModule {}