Intro to Angular2
Key Concepts
• Modules
• Components (Controllers)
• Views(Html)
• Metadata (annotation of class that define how to process the class)
• Data binding (4 types)
• Directives (*ngIF, *ngFor, ngModel) - attribute directives
• Service - (logging, data service, message bus, custom business logic)
• Dependency Injection
Binding Types
Modules
• export class AppComponent { }
• import {AppComponent} from './app.component';
Component
export class AppComponent {
message: string
sayHi(message: string) {
this.message = message;
}
}
Meta data
@Component({
selector: ‘my-app',
templateUrl: 'app/app.component.html',
directives: [HeroDetailComponent],
providers: [HeroService]
})
export class AppComponent { ... }
Data Binding
• <div>{{hero.name}}</div>
• <hero-detail [hero]="selectedHero"></hero-
detail>
• <div (click)=“selectHero(hero)"></div>
• <input [(ngModel)]="hero.name">
Directives
• <div *ngFor="#hero of heroes"></div>
• <hero-detail *ngIf=“selectedHero"></hero-detail>
• <input [(ngModel)]="hero.name">
Service
export class Logger {
log(msg: any) { console.log(msg); }
error(msg: any) { console.error(msg); }
warn(msg: any) { console.warn(msg); }
}
Dependency Injection
@Component({
providers: [HeroService]
})
constructor(private _service: HeroService){ }
• bootstrap(AppComponent, [BackendService,
HeroService, Logger]);
Demos

Brief intro 2 to angular 2

Editor's Notes

  • #3 Data binding value binding (c -> d), property binding (c -> d) e.g. textbook with a value attribute that is bound to a property, event binding (d -> c) event handler, two-way ngModel. Service - Anything that is not a view that has one specific thing to do