2016-09-01 07:00:14 -04:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. 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.io/license
|
|
|
|
*/
|
|
|
|
|
2017-01-25 20:41:08 -05:00
|
|
|
import {CommonModule} from '@angular/common';
|
2019-01-28 15:59:25 -05:00
|
|
|
import {COMPILER_OPTIONS, Compiler, CompilerFactory, Component, Injectable, Injector, NgModule, NgModuleFactory} from '@angular/core';
|
2016-09-01 07:00:14 -04:00
|
|
|
import {BrowserModule} from '@angular/platform-browser';
|
2019-01-28 15:59:25 -05:00
|
|
|
import {JitCompilerFactory} from '@angular/platform-browser-dynamic';
|
2016-09-01 07:00:14 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// #docregion SimpleExample
|
|
|
|
@Component({selector: 'hello-world', template: 'Hello World!'})
|
2019-01-28 15:59:25 -05:00
|
|
|
export class HelloWorld {
|
2016-09-01 07:00:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'ng-component-outlet-simple-example',
|
|
|
|
template: `<ng-container *ngComponentOutlet="HelloWorld"></ng-container>`
|
|
|
|
})
|
2019-01-28 15:59:25 -05:00
|
|
|
export class NgTemplateOutletSimpleExample {
|
2016-09-01 07:00:14 -04:00
|
|
|
// This field is necessary to expose HelloWorld to the template.
|
|
|
|
HelloWorld = HelloWorld;
|
|
|
|
}
|
|
|
|
// #enddocregion
|
|
|
|
|
|
|
|
// #docregion CompleteExample
|
|
|
|
@Injectable()
|
2019-01-28 15:59:25 -05:00
|
|
|
export class Greeter {
|
2017-01-09 14:54:25 -05:00
|
|
|
suffix = '!';
|
2016-09-01 07:00:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'complete-component',
|
|
|
|
template: `Complete: <ng-content></ng-content> <ng-content></ng-content>{{ greeter.suffix }}`
|
|
|
|
})
|
2019-01-28 15:59:25 -05:00
|
|
|
export class CompleteComponent {
|
2016-09-01 07:00:14 -04:00
|
|
|
constructor(public greeter: Greeter) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'ng-component-outlet-complete-example',
|
|
|
|
template: `
|
|
|
|
<ng-container *ngComponentOutlet="CompleteComponent;
|
|
|
|
injector: myInjector;
|
|
|
|
content: myContent"></ng-container>`
|
|
|
|
})
|
2019-01-28 15:59:25 -05:00
|
|
|
export class NgTemplateOutletCompleteExample {
|
2016-09-01 07:00:14 -04:00
|
|
|
// This field is necessary to expose CompleteComponent to the template.
|
|
|
|
CompleteComponent = CompleteComponent;
|
|
|
|
myInjector: Injector;
|
|
|
|
|
|
|
|
myContent = [[document.createTextNode('Ahoj')], [document.createTextNode('Svet')]];
|
|
|
|
|
|
|
|
constructor(injector: Injector) {
|
2018-11-27 10:04:27 -05:00
|
|
|
this.myInjector =
|
|
|
|
Injector.create({providers: [{provide: Greeter, deps: []}], parent: injector});
|
2016-09-01 07:00:14 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// #enddocregion
|
|
|
|
|
2017-01-25 20:41:08 -05:00
|
|
|
// #docregion NgModuleFactoryExample
|
|
|
|
@Component({selector: 'other-module-component', template: `Other Module Component!`})
|
2019-01-28 15:59:25 -05:00
|
|
|
export class OtherModuleComponent {
|
2017-01-25 20:41:08 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'ng-component-outlet-other-module-example',
|
|
|
|
template: `
|
|
|
|
<ng-container *ngComponentOutlet="OtherModuleComponent;
|
|
|
|
ngModuleFactory: myModule;"></ng-container>`
|
|
|
|
})
|
2019-01-28 15:59:25 -05:00
|
|
|
export class NgTemplateOutletOtherModuleExample {
|
2017-01-25 20:41:08 -05:00
|
|
|
// This field is necessary to expose OtherModuleComponent to the template.
|
|
|
|
OtherModuleComponent = OtherModuleComponent;
|
|
|
|
myModule: NgModuleFactory<any>;
|
|
|
|
|
|
|
|
constructor(compiler: Compiler) { this.myModule = compiler.compileModuleSync(OtherModule); }
|
|
|
|
}
|
|
|
|
// #enddocregion
|
|
|
|
|
2016-09-01 07:00:14 -04:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'example-app',
|
|
|
|
template: `<ng-component-outlet-simple-example></ng-component-outlet-simple-example>
|
|
|
|
<hr/>
|
2017-01-25 20:41:08 -05:00
|
|
|
<ng-component-outlet-complete-example></ng-component-outlet-complete-example>
|
|
|
|
<hr/>
|
|
|
|
<ng-component-outlet-other-module-example></ng-component-outlet-other-module-example>`
|
2016-09-01 07:00:14 -04:00
|
|
|
})
|
2019-01-28 15:59:25 -05:00
|
|
|
export class AppComponent {
|
|
|
|
}
|
|
|
|
|
|
|
|
@NgModule({
|
|
|
|
imports: [CommonModule],
|
|
|
|
declarations: [OtherModuleComponent],
|
|
|
|
entryComponents: [OtherModuleComponent]
|
|
|
|
})
|
|
|
|
export class OtherModule {
|
|
|
|
}
|
|
|
|
|
|
|
|
export function createCompiler(compilerFactory: CompilerFactory) {
|
|
|
|
return compilerFactory.createCompiler();
|
2016-09-01 07:00:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
@NgModule({
|
|
|
|
imports: [BrowserModule],
|
|
|
|
declarations: [
|
2019-01-28 15:59:25 -05:00
|
|
|
AppComponent, NgTemplateOutletSimpleExample, NgTemplateOutletCompleteExample,
|
2017-01-25 20:41:08 -05:00
|
|
|
NgTemplateOutletOtherModuleExample, HelloWorld, CompleteComponent
|
2016-09-01 07:00:14 -04:00
|
|
|
],
|
|
|
|
entryComponents: [HelloWorld, CompleteComponent],
|
2019-01-28 15:59:25 -05:00
|
|
|
providers: [
|
|
|
|
// Setup the JIT compiler that is not set up by default because the examples
|
|
|
|
// are bootstrapped using their NgModule factory. Since this example uses the
|
|
|
|
// JIT compiler, we manually set it up for this module.
|
|
|
|
{provide: COMPILER_OPTIONS, useValue: {}, multi: true},
|
|
|
|
{provide: CompilerFactory, useClass: JitCompilerFactory, deps: [COMPILER_OPTIONS]},
|
|
|
|
{provide: Compiler, useFactory: createCompiler, deps: [CompilerFactory]}
|
|
|
|
]
|
2016-09-01 07:00:14 -04:00
|
|
|
})
|
|
|
|
export class AppModule {
|
|
|
|
}
|