【发布时间】:2018-01-08 09:13:13
【问题描述】:
我有两个组件,比如 app-root 和 new-component
我在 app-root 组件中有一个按钮。当我点击按钮时,我每次都需要重新加载新组件。
请指导我,如何做到这一点。
谢谢
【问题讨论】:
标签: angular angular2-routing angular2-services angular2-directives
我有两个组件,比如 app-root 和 new-component
我在 app-root 组件中有一个按钮。当我点击按钮时,我每次都需要重新加载新组件。
请指导我,如何做到这一点。
谢谢
【问题讨论】:
标签: angular angular2-routing angular2-services angular2-directives
您可以轻松地从父组件刷新组件,方法是在组件内创建一个 reload 方法并从 prent 调用,如下所示,
@Component({
selector: 'my-app',
template: `<h1>Hello {{name}}</h1>
<my-child #child ></my-child>
<button (click)="child.refresh()" >Refresh Child</button>
`
})
export class AppComponent {
name = 'World';
}
@Component({
selector: 'my-child',
template: `<h1>Date : {{date}}</h1>`
})
export class ChildComponent {
date = new Date();
refresh(){
this.date = new Date();
}
}
检查这个Plunker!!
【讨论】: