import {Component,Input} from 'angular2/core';
@Component({
selector: 'child',
template: `
<h2>child {{content}}</h2>
`
})
class Child {
@Input() content:string;
}
@Component({
selector: 'App',
directives: [Child],
template: `
<h1>App</h1>
<child [content]="i"></child>
`
})
export class App {
i:number = 0;
constructor() {
setInterval(()=> {
this.i++;
}, 1000)
}
}
import {Output,EventEmitter,Component} from 'angular2/core';
@Component({
selector: 'child',
template: `
<h2>child</h2>
`
})
class Child {
@Output() updateNumberI:EventEmitter<number> = new EventEmitter();
i:number = 0;
constructor() {
setInterval(()=> {
this.updateNumberI.emit(++this.i);
}, 1000)
}
}
@Component({
selector: 'App',
directives: [Child],
template: `
<h1>App {{i}}</h1>
<child (updateNumberI)="numberIChange($event)"></child>
`
})
export class App {
i:number = 0;
numberIChange(i:number){
this.i = i;
}
}
import {Host,Component,forwardRef} from 'angular2/core';
@Component({
selector: 'child',
template: `
<h2>child</h2>
`
})
class Child {
constructor(@Host() @Inject(forwardRef(()=> App)) app:App) {
setInterval(()=> {
app.i++;
}, 1000);
}
}
@Component({
selector: 'App',
directives: [Child],
template: `
<h1>App {{i}}</h1>
<child></child>
`
})
export class App {
i:number = 0;
}
import {ViewChild,Component} from 'angular2/core';
@Component({
selector: 'child',
template: `
<h2>child {{i}}</h2>
`
})
class Child {
i:number = 0;
}
@Component({
selector: 'App',
directives: [Child],
template: `
<h1>App {{i}}</h1>
<child></child>
`
})
export class App {
@ViewChild(Child) child:Child;
ngAfterViewInit() {
setInterval(()=> {
this.child.i++;
}, 1000)
}
}
import {Component,Injectable} from 'angular2/core';
@Injectable();
class KittencupService {
i:number = 0;
}
@Component({
selector: 'child',
template: `
<h2>child {{service.i}}</h2>
`
})
class Child {
constructor(public service:KittencupService){
}
}
@Component({
selector: 'App',
directives: [Child],
providers: [KittencupService],
template: `
<h1>App {{i}}</h1>
<child></child>
`
})
export class App {
constructor(service:KittencupService) {
setInterval(()=> {
service.i++;
}, 1000)
}
}
import {Component,Injectable,EventEmitter} from 'angular2/core';
@Injectable()
class KittencupService {
change: EventEmitter<number>;
constructor(){
this.change = new EventEmitter();
}
}
@Component({
selector: 'child',
template: `
<h2>child {{i}}</h2>
`
})
class Child {
public i:number = 0;
constructor(public service:KittencupService){
service.change.subscribe((value:number)=>{
this.i = value;
})
}
}
@Component({
selector: 'App',
directives: [Child],
providers: [KittencupService],
template: `
<h1>App {{i}}</h1>
<child></child>
`
})
export class App {
i:number = 0;
constructor(service:KittencupService) {
setInterval(()=> {
service.change.emit(++this.i);
}, 1000)
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有