On Github jeremyalan / Angular2-WhatToExpect
by Jeremy Mason
$scope.$digest();
angular.module(...)
<module>.controller(...)
noun; a part or element of a larger whole
.disabled
.value
.click()
.focus()
.on('click', ...).on('change', ...)<media></media>
<media title="Hello {{ user.Name }}"></media>
<media [url]="media.url"></media>
<media bind-url="media.url"></media>
<media (play)="onPlay($event)"></media>
<media on-play="onPlay($event)"></media>
<media title="{{ media.title | uppercase }}"></media>export class Pipe {
// True if the value can be transformed.
// False, otherwise.
supports(obj): boolean;
// Transforms the value.
transform(obj);
// Cleans up this instance.
onDestroy();
}<my-component> <label>Your name: <label> <input #name /> <button (click)="sayHello(name.value)">Say Hello</button> </my-component>
class MyComponent {
sayHello(name: string) {
alert('Hello ' + name + '!');
}
}
<ul>
<li *ng-for="#user in users">
<span>{{ user.Name }}</span>
</li>
</ul>
<template [ng-for] #user [ng-for-of]="users">...</template>
<div *ng-if="isError"> Login failed, please try again. </div>
<template [ng-if]="isError">...</template>
<my-component>
<header>
<!-- Header -->
</header>
<main>
<!-- Content -->
</main>
<footer>
<!-- Footer -->
</footer>
</my-component>
<div class="container">
<div class="header">
<content select="header"></content>
</div>
<div class="main-content-wrapper">
<div class="main-content">
<content select="main"></content>
</div>
</div>
<div class="footer">
<content select="footer"></content>
</div>
</div>
import {Component, View, bootstrap, NgFor} from 'angular2/angular2';
import {ItemStore} from 'services/ItemStore';
@Component({
selector: 'my-app',
appInjector: [ItemStore]
})
@View({
templateUrl: 'templates/my-app.html',
directives: [NgFor]
})
class MyApp {
_itemStore: ItemStore;
constructor(itemStore: ItemStore) {
this._itemStore = itemStore;
}
add($event, input) {
this._itemStore.add(input.value);
input.value = '';
}
}
bootstrap(MyApp);class MyApp {
constructor() {
}
add($event, input) {
}
}import {bootstrap} from 'angular2/angular2';
class MyApp {
constructor() {
}
add($event, input) {
}
}
bootstrap(MyApp);import {Component, View, bootstrap, NgFor} from 'angular2/angular2';
import {ItemStore} from 'services/ItemStore';
@Component({
selector: 'my-app'
appInjector: [ItemStore]
})
@View({
templateUrl: 'templates/my-app.html',
directives: [NgFor]
})
class MyApp {
constructor(itemStore: ItemStore) {
}
add($event, input) {
}
}
bootstrap(MyApp);@Class
class MyClass {
@Method
myMethod(@Param myParam) {
...
}
}
function MyClass() {
...
}
MyClass.annotations = [
new Foo()
]
@Directive({
selector:
'<css-selector>',
properties:
[
'propName',
'propName: attrName',
'propName: attrName | pipe'
],
events:
[
'<event-name>'
]
// and more ...
})import {MyService} from '...';
@Component({
// Same as @Directive
appInjector:
[ MyService ]
// and more ...
})import {DirectiveType} from '...';
@View({
template:
'<div></div>',
templateUrl:
'path/to/template.html',
directives:
[ DirectiveType ]
// and more ...
})import {MyService} from '...';
@Component({
selector: '...',
appInjector: [ MyService ]
})
class MyComponent {
constructor(myService: MyService) {
...
}
}ElementRef
ViewContainerRef
BindingPropagation
<no-decoration>
@Ancestor
@Parent
@Query
@QueryDescendants
<tabset>
<tab>
...
</tab>
</tabset>
import {TabSet} from '...';
@Component({
selector: 'tab'
})
class Tab {
constructor(@Parent() tabs: TabSet) {
...
}
}
<form [control-group]="searchForm"> <label>Name</label> <input type="text" control="name" /> </form>
import {View} from 'angular2/angular2';
import {FormBuilder, Validators, formDirectives, ControlGroup} from 'angular2/forms';
class LoginComponent {
searchForm: ControlGroup;
constructor(builder: FormBuilder) {
this.searchForm = builder.group({
name: ["", Validators.required]
});
}
}
MyController.$routeConfig = [
{
path: '/user',
components:
{
master: 'userList',
detail: 'user'
}
}
];
<div ng-viewport="master"></div> <div ng-viewport="detail"></div>