refactor(core): change module semantics

This contains major changes to the compiler, bootstrap of the platforms
and test environment initialization.

Main part of #10043
Closes #10164

BREAKING CHANGE:
- Semantics and name of `@AppModule` (now `@NgModule`) changed quite a bit.
  This is actually not breaking as `@AppModules` were not part of rc.4.
  We will have detailed docs on `@NgModule` separately.
- `coreLoadAndBootstrap` and `coreBootstrap` can't be used any more (without migration support).
  Use `bootstrapModule` / `bootstrapModuleFactory` instead.
- All Components listed in routes have to be part of the `declarations` of an NgModule.
  Either directly on the bootstrap module / lazy loaded module, or in an NgModule imported by them.
This commit is contained in:
Tobias Bosch
2016-07-18 03:50:31 -07:00
parent ca16fc29a6
commit 46b212706b
129 changed files with 3580 additions and 3366 deletions

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/
import {AppModule, ApplicationRef, Compiler, CompilerFactory, ComponentFactory, ComponentResolver, Injector, NgZone, PlatformRef, Provider, ReflectiveInjector, Testability, Type, bootstrapModuleFactory, provide} from '@angular/core';
import {ApplicationRef, Compiler, CompilerFactory, ComponentFactory, ComponentResolver, Injector, NgModule, NgZone, PlatformRef, Provider, ReflectiveInjector, Testability, Type, bootstrapModuleFactory, provide} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {browserDynamicPlatform} from '@angular/platform-browser-dynamic';
@ -279,18 +279,19 @@ export class UpgradeAdapter {
var upgrade = new UpgradeAdapterRef();
var ng1Injector: angular.IInjectorService = null;
var platformRef: PlatformRef = browserDynamicPlatform();
var compiler: Compiler = platformRef.injector.get(CompilerFactory).createCompiler();
var providers = [
{provide: NG1_INJECTOR, useFactory: () => ng1Injector},
{provide: NG1_COMPILE, useFactory: () => ng1Injector.get(NG1_COMPILE)}, this.providers
];
@AppModule({providers: providers, modules: [BrowserModule]})
@NgModule({providers: providers, imports: [BrowserModule]})
class DynamicModule {
}
var moduleRef =
bootstrapModuleFactory(compiler.compileAppModuleSync(DynamicModule), platformRef);
const compilerFactory: CompilerFactory = platformRef.injector.get(CompilerFactory);
var moduleRef = bootstrapModuleFactory(
compilerFactory.createCompiler().compileModuleSync(DynamicModule), platformRef);
const boundCompiler: Compiler = moduleRef.injector.get(Compiler);
var applicationRef: ApplicationRef = moduleRef.injector.get(ApplicationRef);
var injector: Injector = applicationRef.injector;
var ngZone: NgZone = injector.get(NgZone);
@ -304,7 +305,7 @@ export class UpgradeAdapter {
var ng1compilePromise: Promise<any> = null;
ng1Module.value(NG2_INJECTOR, injector)
.value(NG2_ZONE, ngZone)
.value(NG2_COMPILER, compiler)
.value(NG2_COMPILER, boundCompiler)
.value(NG2_COMPONENT_FACTORY_REF_MAP, componentFactoryRefMap)
.config([
'$provide', '$injector',
@ -384,7 +385,7 @@ export class UpgradeAdapter {
});
Promise.all([ng1BootstrapPromise, ng1compilePromise])
.then(() => { return this.compileNg2Components(compiler, componentFactoryRefMap); })
.then(() => { return this.compileNg2Components(boundCompiler, componentFactoryRefMap); })
.then(() => {
ngZone.run(() => {
if (rootScopePrototype) {