简体   繁体   English

在同一页面上加载多个组件 Angular 2

[英]Load multiple componant on the same page Angular 2

I'm working on an angular 2 application, to keep the explication short, I have a navbar on the left, and on the rest of the page, and I will display my content.我正在开发一个 angular 2 应用程序,为了保持简短,我在左侧和页面的其余部分有一个导航栏,我将显示我的内容。

Those content will be blocks, as in the attached image, the navbar contains 4 actions (Form, test1, details ...)这些内容将是块,如附加图像中所示,导航栏包含 4 个操作(表单、测试 1、详细信息...)

The content in the middle will display everything, but when I click on form, form will be shown in the middle, when i click on Details, the details block will be shown in the middle.中间的内容将显示所有内容,但是当我单击表单时,表单将显示在中间,当我单击详细信息时,详细信息块将显示在中间。

The user can scroll down and up to see the blocks.用户可以向下和向上滚动以查看块。

I saw that in Angular 2 we can user Fragment to precise anchor and what blocks we want to show, but the problem is that there is a bug on the fragment functionality.我看到在 Angular 2 中我们可以使用 Fragment 来精确定位和我们想要显示的块,但问题是片段功能存在错误。

At the moment, I have a router-outlet that changes the view depending on the url in the routerLink on each button of the navbar.目前,我有一个路由器插座,它根据导航栏每个按钮上 routerLink 中的 url 更改视图。 Should I keep using it if i want to display all the blocks/components on the same page?如果我想在同一页面上显示所有块/组件,我应该继续使用它吗?

Thanks for your help,谢谢你的帮助,

here is the screenshot这是屏幕截图

So in essence, you want a multitude of components, with a menu that doesn't really navigate, but more so has toggle buttons that either display or hide content?所以从本质上讲,您想要多个组件,带有一个并不真正导航的菜单,但更多的是具有显示或隐藏内容的切换按钮? What should a page refresh do?页面刷新应该做什么? Does it matter if you see the same components then?如果您看到相同的组件,这是否重要? If so, you either have to store state in local storage / session storage / using ngrx... or you have to add the displayed items to the route and resolve those.如果是这样,您要么必须将状态存储在本地存储/会话存储/使用 ngrx... 中,或者您必须将显示的项目添加到路由中并解决它们。

Anyhow, in the end you want one component which decides what is displayed, and all the blocks in their own components with their own selectors which you show / hide using *ngIf.无论如何,最终您需要一个决定显示内容的组件,以及它们自己的组件中的所有块以及您使用 *ngIf 显示/隐藏的自己的选择器。

Your html would basically look like this:你的 html 基本上是这样的:

<my-menu></my-menu>
<my-form *ngIf="showMenu"></my-form>
<my-test1 *ngIf="showTest1"></my-test1>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM