【发布时间】:2016-09-30 05:19:03
【问题描述】:
当我们导航到一个路由并加载组件时,
- 我们可以在加载的子组件中传递带有
@Input修饰的变量吗?我们可以订阅带有@Output修饰的EventEmitter吗? - 父组件中是否有
lifecycle Hook可用,其中定义了Route,我们可以获取加载的组件的引用,从而将值\订阅函数动态传递给子组件?
父组件
@Component({
moduleId: module.id,
selector: "parent",
templateUrl: "<router-outlet></router-outlet>"
})
@Routes([
{ path: "/child-component1", component: Child1Component }
])
export class Parent {
// Can we pass var1 and subscribe close here of Child1Component when route is navigated dynamically based upon path?
// Is there any lifecycleHook available in parent where Route is defined?
}
子组件
@Component({
moduleId: module.id,
selector: "child-component1",
template: "<div>{{var1}}</div><button (click)='closeMenu()'>Close</button>"
})
export class Child1Component {
@Input() var1: string;
@Output() close: EventEmitter<any> = new EventEmitter<any>();
constructor() { }
closeMenu = (): void => {
this.close.emit("");
}
}
我正在使用Angular2 RC1
提前致谢!
【问题讨论】:
标签: angularjs typescript angular angular2-routing typescript1.8