Load self in modal - Angular component

廉价感情. 提交于 2019-12-13 10:31:27

问题


I need to load component in a modal when you access it via it's URL. Need help figuring how that setup should be, I have ngxbootstrap on an angular component and can popup modals in response to e.g.a button click. Can't find anything that shows how entire component template would be loaded in modal when component URL is accessed.

Thanks


回答1:


You need to have one component for the route, and in it's ngOnInit you can open a modal with the component you want in the modal.

To make it reusable, you could have a route component that opens a modal with any component passed to it in route data. I assume this would only make sense for child routes, otherwise it'd just be a modal on a blank background, so example:

const childRoutes = [
    { path: 'route1', component: ModalRouteComponent, data: { component: MyModalComponent1 }},
    { path: 'route2', component: ModalRouteComponent, data: { component: MyModalComponent2 }}
];

ModalRouteComponent:

ngOnInit() {
    this.route.data.subscribe(data => this.openModal(data.component));
}


来源:https://stackoverflow.com/questions/49014487/load-self-in-modal-angular-component

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!