feat(platform-browser-dynamic): export JitCompilerFactory
(#20478)
Fixes #20125 PR Close #20478
This commit is contained in:

committed by
Miško Hevery

parent
437a0446e2
commit
d7a727cc07
27
integration/dynamic-compiler/src/app.component.ts
Normal file
27
integration/dynamic-compiler/src/app.component.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import {AfterViewInit, Compiler, Component, ViewChild, ViewContainerRef} from '@angular/core';
|
||||
|
||||
declare var System: any;
|
||||
|
||||
@Component({
|
||||
selector: 'app-root',
|
||||
template: `
|
||||
<h1>Hello world!</h1>
|
||||
<div #vc></div>
|
||||
`,
|
||||
})
|
||||
export class AppComponent implements AfterViewInit {
|
||||
@ViewChild('vc', {read: ViewContainerRef}) container: ViewContainerRef;
|
||||
|
||||
constructor(private compiler: Compiler) {
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
System.import('./dist/lazy.bundle.js').then((module: any) => {
|
||||
this.compiler.compileModuleAndAllComponentsAsync(module.LazyModule)
|
||||
.then((compiled) => {
|
||||
const factory = compiled.componentFactories[0];
|
||||
this.container.createComponent(factory);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
22
integration/dynamic-compiler/src/app.module.ts
Normal file
22
integration/dynamic-compiler/src/app.module.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import {Compiler, COMPILER_OPTIONS, CompilerFactory, NgModule} from '@angular/core';
|
||||
import { BrowserModule } from '@angular/platform-browser';
|
||||
import {JitCompilerFactory} from '@angular/platform-browser-dynamic';
|
||||
|
||||
import { AppComponent } from './app.component';
|
||||
|
||||
export function createCompiler(compilerFactory: CompilerFactory) {
|
||||
return compilerFactory.createCompiler();
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
imports: [BrowserModule],
|
||||
bootstrap: [AppComponent],
|
||||
declarations: [AppComponent],
|
||||
providers: [
|
||||
{provide: COMPILER_OPTIONS, useValue: {}, multi: true},
|
||||
{provide: CompilerFactory, useClass: JitCompilerFactory, deps: [COMPILER_OPTIONS]},
|
||||
{provide: Compiler, useFactory: createCompiler, deps: [CompilerFactory]}
|
||||
]
|
||||
})
|
||||
export class AppModule {}
|
||||
|
17
integration/dynamic-compiler/src/lazy.module.ts
Normal file
17
integration/dynamic-compiler/src/lazy.module.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import {NgModule} from "@angular/core";
|
||||
import {Component} from '@angular/core';
|
||||
|
||||
@Component({
|
||||
selector: 'lazy-component',
|
||||
template: 'Lazy-loaded component!'
|
||||
})
|
||||
export class LazyComponent {
|
||||
constructor() {
|
||||
}
|
||||
}
|
||||
|
||||
@NgModule({
|
||||
declarations: [LazyComponent]
|
||||
})
|
||||
export class LazyModule {
|
||||
}
|
8
integration/dynamic-compiler/src/main.ts
Normal file
8
integration/dynamic-compiler/src/main.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { enableProdMode } from '@angular/core';
|
||||
import { platformBrowser } from '@angular/platform-browser';
|
||||
|
||||
import { AppModuleNgFactory } from './app.module.ngfactory';
|
||||
|
||||
enableProdMode();
|
||||
|
||||
platformBrowser().bootstrapModuleFactory(AppModuleNgFactory);
|
Reference in New Issue
Block a user