import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { BrowserModule } from '@angular/platform-browser';
import { NgModule, Component, OnInit } from '@angular/core';
class Hero { id: number; name: string; }
@Component({ ... })
class AppComponent implements OnInit { ... }
@NgModule({})
export class AppModule { ... }
platformBrowserDynamic().bootstrapModule(AppModule);
const HEROES: Hero[] = [
{id: 1, name: 'Batman'},
...
];
function getHeroes(): Promise {
return Promise.resolve(HEROES);
}
@Component({ ... })
export class AppComponent { }
@Pipe({ name: 'initCaps' }) export class InitCapsPipe implements PipeTransform { }
@Injectable() export class UserProfileService { }
@Component({ selector: 'wac-hero' }) export class HeroComponent {}
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { HeroesComponent } from './heroes/heroes.component';
import { CoreModule } from './core/core.module';
@NgModule({
imports: [
BrowserModule,
CoreModule,
],
declarations: [
AppComponent,
HeroesComponent
],
exports: [ AppComponent ],
entryComponents: [ AppComponent ]
})
export class AppModule {}
6.1 Use one-way data binding
Keeps data changes predictable and in-sync
6.2 Avoid referencing local template variables
6.3 Avoid side-effects in template expressions
6.4 Use the NgClass directive for managing multiple class names at the same time
6.5 Use the NgStyle directive when setting several inline styles at the same time
6.6 Use property binding with ngSwitch