【发布时间】:2018-03-24 07:12:50
【问题描述】:
在我的 Angular 2 应用程序中,我有 app.module 和 app.component app.component 是我的父组件,在其中,我有路由器出口来根据我的路线加载页面。 基于我的一个组件中的事件加载基于我想在我的应用程序组件中触发事件的路由。是否有可能,如果可以,该怎么做。
【问题讨论】:
标签: javascript angular typescript angular2-routing
在我的 Angular 2 应用程序中,我有 app.module 和 app.component app.component 是我的父组件,在其中,我有路由器出口来根据我的路线加载页面。 基于我的一个组件中的事件加载基于我想在我的应用程序组件中触发事件的路由。是否有可能,如果可以,该怎么做。
【问题讨论】:
标签: javascript angular typescript angular2-routing
是的,您必须在子组件的 ngOnInit 中触发输出事件发射器。
所以在您的子组件中,您将拥有
@Output() myEventOnInit= new EventEmitter<dataType>();
ngOnInit() {
myEventOnInit.emit(myData)
}
然后在你的 app.component 模板中:
<my-child-componant (myEventOnInit)="myFunctionThatHanddleTHeInitComponant($event)"></my-child-componant>
myFunctionThatHanddleTHeInitComponant 是您必须在父组件中描述的函数。
我希望它对你有所帮助,并且我已经理解了你的问题。
【讨论】: