by @laco0416
http://ng-sake.connpass.com/
import {NgModule, ApplicationRef} from '@angular/core';
import {CommonModule} from '@angular/common';
import {FormsModule} from '@angular/forms';
import {MaterialModule} from '@angular2-material/module';
import {AppComponent} from './app.component';
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule, CommonModule, FormsModule, MaterialModule],
entryComponents: [AppComponent]
})
class AppModule {
constructor(appRef: ApplicationRef) {
appRef.bootstrap(AppComponent);
}
}
import {AppModule} from './app.module';
import {platformBrowserDynamic} from '@angular/browser-platform-dynamic';
platformBrowserDynamic().bootstrapModule(AppModule);
class NgModule {
declarations: Array<ComponentType | DirectiveType | PipeType>;
imports: Array<ModuleType | ModuleWithProviders>;
exports: Array<ComponentType | DirectiveType | PipeType | ModuleType>;
providers: Array<Providers | Array<any> >;
entryComponents: Array<ComponentType>;
schemas: Array<any>;
}
@NgModule({
declarations: [
AppComponent,
MyComponent,
MyDirective,
MyPipe,
...SOME_LIBRALIES_DIRECTIVES
],
})
@NgModule({
providers: [
MyService,
SomeLibraryService,
],
})
@NgModule({
declarations: [AwesomeComponent, AwesomePipe]
exports: [AwesomeComponent, AwesomePipe],
providers: [AwesomeService]
})
export class AwesomeModule {
}
Legacy | New |
---|---|
bootstrap(.., [MyService]) | NgModule.providers |
Component.pipes | NgModule.declarations |
Component.directives | NgModule.declarations |
Component.providers | NgModule.providers |
@Component({
directives: [ MyComponent ],
pipes: [ MyPipe ],
providers: [ MyService ],
})
class AppComponent {
}
bootstrap(AppComponent, [
HTTP_PROVIDERS
])
import {bootstrap} from '@angular/browser-platform-dynamic';
import {AppComponent} from './app.component';
import {FormsModule} from '@angular/forms';
bootstrap(AppComponent, {imports: [FormsModule]});
for migration
angular.module('app', ['ui.router'])
.service('myService', MyService)
.component('myComponent', {...})
.config(() => {...});
@NgModule({
imports: [RouterModule],
delcarations: [MyComponent],
providers: [MyService]
})
class AppModule {
constructor() {
...
}
}