import {Component} from 'angular2/core';
@Component({
selector: 'app',
template: '<h1>Hello World</h1>'
})
export class Application {}
export default class Timer {
getCurrentTime(){
return new Date();
}
}
import {Component} from 'angular2/core';
import Timer from './Timer';
@Component({
selector: 'currentTime',
template: '<span>{{currentTime}}</span>',
providers: [Timer]
})
export class CurrentTime {
constructor(private timer:Timer){
this.currentTime = this.timer.getCurrentTime()
}
}
A Pipe it's a function that transform data, just like AngularJS filters.
import {Pipe, PipeTransform} from 'angular2/core';
@Pipe({name: 'checkmark'})
export default class CheckmarkPipe implements PipeTransform {
transform(input){
return input ? '\u2713' : '\u2718';
}
}
import {Component} from 'angular2/core';
@Component({
selector: 'app',
template: '<h1>Hello, {{message}}!</h1>'
})
export class Application {
message;
constructor(){
this.message = 'e-xtrategy';
}
}
import {Component} from 'angular2/core';
@Component({
selector: 'Swapper',
template: `
<div>
<input #first />
<input #second />
<button (click)="swap(first,second)">Swap</button>
</div>`
})
export class Swapper {
constructor(){}
swap(first,second){
let firstValue = first.value;
let secondValue = second.value;
first.value = secondValue;
second.value = firstValue;
}
}
@Component({
selector: 'child',
templateUrl: 'app/components/Child.tpl.html',
inputs:['input1'],
outputs: ['event1']
})
export default class Child {
event1;
input1;
constructor(){
this.event1 = new EventEmitter();
}
whenSomethingHappens(){
this.event1.emit('value');
}
}
Observable.fromEvent(inputElement, 'keyup')
.map((e) => e.target.value)
.filter((text) => text.length > 1)
.debounceTime(250)
.do(() => startLoading())
.map((query) => this.asyncService(query))
.switch()
You could use Rx/Js to:
var userFactory = function(id,name,age){
var toReturn = {
id:id,
name:name
};
if(age){
toReturn.age = age;
}
return toReturn;
};
(Linus Torvalds)