我使用Angular2搜索组件之间的通信我尝试在这种模式下但不起作用
模板 variantpages.component.html 内容
<button (click)="changetext()">Change</button>
<child></child>
@Component({
selector: 'menu-left',
templateUrl: './app/pages/variantpages.component.html'
})
export class AppComponent{
child = new ChildComponent();
changetext(){ this.child.changetext2()}
}
@Component({
selector: 'child',
template: `<p>page of {{ pageCount }}</p>`
})
export class ChildComponent{
@Input() photo:string = "ciao ciao";
@Output() valueChange = new EventEmitter();
pageCount:number;
constructor(){ this.pageCount = 0; }
changetext2(){
this.pageCount++;
this.valueChange.emit(this.pageCount);
console.log(this.pageCount);
}
}
所以控制台日志显示增量数,但 pageCount 保持为 0
谢谢