2016
2016
2
var variableName: variableType = value; let variableName2: variableType = value; const variableName3: variableType = value;
let isDone: boolean = false;
const height: number = 6;
let name: string = 'Carl';
let names: string[] = ['Carl', 'Laurent'];
let notSure: any = 4;
class Person { constructor() {} speak:String() {return 'Yay';} }
class Child extends Person { constructor() {super();} speak:String() {return 'Nay';} } let person:Person = new Child();
}
app.directive('MyDirective', function(){
return {
restrict: 'AE',
require: '?^^ngModel',
scope: { variable: '@' },
controller: function(...) {},
link: function(...) { ... }
}
});2
2
app.directive('MyDirective', function(){
return {
restrict: 'AE',
require: '?^^ngModel',
scope: { variable: '@' },
controller: function(...) {},
link: function(...) { ... }
}
});2
import { Component, Input} from '@angular/core'
@Component({
selector: 'my-component',
templateUrl: 'myComponent.html' }) export class MyComponent { @Input() variable:string; }
Angular 2
Syntax
//provider, factory, constant and value
app.service('Service', ['$http' function($http){
var vm = this;
vm.myMethod = function(){
}
}]);
@Injectable()
export class AccountService {
constructor(http){}
getAccountByName(name: String){}
}
2
import { AccountService} from './AccountService'
@Component(...)
export class AccountDetailComponent {
getAccount() { return this.accountService.getAccountByName('John'); }
constructor(accountService:AccountService){}
}
Angular2 dep injection syntax based on Typescript
2
2
Reactive Functionnal Programming
<input type="text" [ngFormControl]="term"/>
this.items = this.term.valueChanges
.debounce(400)
.map(term => term.trim()) .distinctUntilChanged() .subscribe(term => this.wk.search(term));
2
2
https://angular.io/docs/ts/latest/guide/upgrade.html
2
Thanks!
http://tinyurl.com/zenika27102016