0
我正在Angular2中構建一個應用程序。我有兩個組件,其中第二個組件加載到第一個組件的路由器插座中。Angular2中的兩個組件之間的通信
Component 1
@Component({
selector: 'component1',
templateUrl: '
<div>
...
...
...
</div>
<router-outlet></router-outlet>
'
})
@RouteConfig([
{ path: '/component2', component: Component2, name: 'Component2', useAsDefault: true }])
export class Component1{
...
...
...
refresh(){
...
...
}
}
現在這裏是Component2。
@Component({
selector: 'component2',
templateUrl: '
<div>
...
...
...
</div>
'
})
export class Component2{
...
...
...
thisFunctionShouldRefreshComponent1(){
//call Component1's refresh here
}
有人可以告訴我如何從組件2調用Component1的刷新方法。
你需要在這兩種成分注入的服務。 –
https://angular.io/docs/ts/latest/cookbook/component-communication.html –