ZoneJS
import {Component} from 'angular2/core';
import {DialogComponent} from './dialog';
import {AppState} from './app.service';
@Component({
selector: 'app',
directives: ['DialogComponent']
template: require('./app.component.html')
})
export class App {
constructor(public appState: AppState) {}
ngOnInit() {
console.log('Initial App State', this.appState.state);
}
}
<img [src] = "logo.image">
<dialog [title]="You created a Dialog!">
<div [ngClass] = "{selected: isSelected}">
</div>
</dialog>Presentation carefully prepared by
Martin Muzatko
@martinmuzatko
More dev stuff by Martin?
Looking for an awesome company to work with?
| ngOnInit |
Initialize the directive/component after Angular initializes the data-bound input properties. |
| ngOnChanges |
Respond after Angular sets a data-bound input property. The method receives a changes object of current and previous values. |
| ngDoCheck |
Detect and act upon changes that Angular can or won't detect on its own. Called every change detection run. |
| ngOnDestroy |
Cleanup just before Angular destroys the directive/component. Unsubscribe observables and detach event handlers to avoid memory leaks. |
Component Based
| ngAfterContentInit |
After Angular projects external content into its view. |
| ngAfterContentChecked |
After Angular checks the bindings of the external content that it projected into its view. |
| ngAfterViewInit |
After Angular creates the component's view(s). |
| ngAfterViewChecked |
After Angular checks the bindings of the component's view(s). |
Many JavaScript expressions are legal template expressions, but not all.
JavaScript expressions that have or promote side effects are prohibited, including:
Context/Scope
Only to "This" Which means if you define a variable in your class:
export class App {
logo = 'assets/img/logo.png';
version = '1.5.t';
os = [
{
title: 'Ubuntu',
vendor: 'Canonical'
},
{
title: 'Windows',
vendor: 'Microsoft'
},
{
title: 'OS X',
vendor: 'Apple'
},
]
}<div>
<img src="{{logo}}">
Version: {{version}}
<ul>
<li *ngFor="#system of os">
{{system.title}} - {{system.vendor}}
</li>
</ul>
</div>import {Http, HTTP_PROVIDERS} from 'angular2/http';
@Component({
selector: 'http-app',
viewProviders: [HTTP_PROVIDERS],
templateUrl: 'people.html'
})
class PeopleComponent {
constructor(http: Http) {
http.get('people.json')
.map(res => res.json())
.subscribe(people => this.people = people);
}
}Angular2 HTTP Responses are handled with the Observable
Path based
This requires additional server configuration!
Example: /app/view/admin
Location based
Uses the Hash
example: #app/view/admin
Setup
@Component({ ... })
@RouteConfig([
{path:'/crisis-center', name: 'CrisisCenter', component: CrisisListComponent},
{path:'/heroes', name: 'Heroes', component: HeroListComponent}
])
export class AppComponent { }