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:
@ -7,7 +7,7 @@
|
||||
*/
|
||||
|
||||
import {LowerCasePipe, NgIf} from '@angular/common';
|
||||
import {ANALYZE_FOR_PRECOMPILE, AppModule, Component, ComponentFactoryResolver, Directive, Inject, Injectable, Input, OpaqueToken, Pipe} from '@angular/core';
|
||||
import {ANALYZE_FOR_PRECOMPILE, Component, ComponentFactoryResolver, Directive, Inject, Injectable, Input, NgModule, OpaqueToken, Pipe} from '@angular/core';
|
||||
import {BrowserModule} from '@angular/platform-browser';
|
||||
|
||||
@Injectable()
|
||||
@ -16,50 +16,37 @@ export class SomeService {
|
||||
}
|
||||
|
||||
@Injectable()
|
||||
export class NestedService {
|
||||
export class ServiceUsingLibModule {
|
||||
}
|
||||
|
||||
@Directive({selector: '[someDir]', host: {'[title]': 'someDir'}})
|
||||
export class SomeDirective {
|
||||
export class SomeDirectiveInRootModule {
|
||||
@Input()
|
||||
someDir: string;
|
||||
}
|
||||
|
||||
@Directive({selector: '[someDir]', host: {'[title]': 'someDir'}})
|
||||
export class SomeDirectiveInLibModule {
|
||||
@Input()
|
||||
someDir: string;
|
||||
}
|
||||
|
||||
@Pipe({name: 'somePipe'})
|
||||
export class SomePipe {
|
||||
export class SomePipeInRootModule {
|
||||
transform(value: string): any { return `transformed ${value}`; }
|
||||
}
|
||||
|
||||
@Component({selector: 'cmp', template: `<div [someDir]="'someValue' | somePipe"></div>`})
|
||||
export class SomeComp {
|
||||
constructor() {}
|
||||
@Pipe({name: 'somePipe'})
|
||||
export class SomePipeInLibModule {
|
||||
transform(value: string): any { return `transformed ${value}`; }
|
||||
}
|
||||
|
||||
@Component({selector: 'parent', template: `<cmp></cmp>`, directives: [SomeComp]})
|
||||
export class ParentComp {
|
||||
@Component({selector: 'comp', template: `<div [someDir]="'someValue' | somePipe"></div>`})
|
||||
export class CompUsingRootModuleDirectiveAndPipe {
|
||||
}
|
||||
|
||||
@AppModule({providers: [NestedService]})
|
||||
export class NestedModule {
|
||||
}
|
||||
|
||||
@AppModule({
|
||||
directives: [SomeDirective],
|
||||
pipes: [SomePipe],
|
||||
providers: [SomeService],
|
||||
precompile: [SomeComp],
|
||||
modules: [NestedModule, BrowserModule]
|
||||
})
|
||||
export class SomeModule {
|
||||
}
|
||||
|
||||
@AppModule({
|
||||
directives: [SomeDirective],
|
||||
pipes: [SomePipe],
|
||||
precompile: [ParentComp],
|
||||
modules: [BrowserModule]
|
||||
})
|
||||
export class SomeModuleUsingParentComp {
|
||||
@Component({selector: 'comp', template: `<div [someDir]="'someValue' | somePipe"></div>`})
|
||||
export class CompUsingLibModuleDirectiveAndPipe {
|
||||
}
|
||||
|
||||
export const SOME_TOKEN = new OpaqueToken('someToken');
|
||||
@ -71,7 +58,13 @@ export function provideValueWithPrecompile(value: any) {
|
||||
];
|
||||
}
|
||||
|
||||
@AppModule({providers: [provideValueWithPrecompile([{a: 'b', component: SomeComp}])]})
|
||||
export class SomeModuleWithAnalyzePrecompileProvider {
|
||||
constructor(@Inject(SOME_TOKEN) public providedValue: any) {}
|
||||
@NgModule({
|
||||
declarations: [SomeDirectiveInLibModule, SomePipeInLibModule, CompUsingLibModuleDirectiveAndPipe],
|
||||
precompile: [CompUsingLibModuleDirectiveAndPipe],
|
||||
providers: [
|
||||
ServiceUsingLibModule,
|
||||
provideValueWithPrecompile([{a: 'b', component: CompUsingLibModuleDirectiveAndPipe}])
|
||||
],
|
||||
})
|
||||
export class SomeLibModule {
|
||||
}
|
||||
|
Reference in New Issue
Block a user