Angular 2如何分别加载2 App根组件 [英] Angular 2 How to load 2 App root component separately
问题描述
是否可以加载2个不同的根组件(不在页面中并排加载). 找到了一个 plunker示例,唯一的区别是这两个根组件都在单个页面中加载.
Is it possible to load 2 different root components (not side by side in page). Found a plunker example, only differences is that both of the root component is loaded in a single page.
<body>
<my-app>Loading...</my-app>
<my-sec>Loading...</my-sec>
</body>
我想要实现的是每个组件都有各自的布局,并且不与app.component共享.
What I want to achieve is that so each of the component have their own layout and not shared with the app.component.
示例:app.component将具有普通用户的视图模板,而admin.component将具有仪表板模板.
Example: app.component would have a view template for normal users where as admin.component would have dashboard template.
这可以实现吗?或者我必须为此创建2个单独的项目?(一个用于普通视图,另一个用于仪表板视图)
Is this achievable? or I have to create 2 separate project for this?(One for normal view other for dashboard view)
推荐答案
尽管我找不到正确的答案,但这是经过几天的尝试后得出的.这足以满足我的需求.
Although I couldn't figure out the correct answer, this is what I came up with after few days of playing around with it. This is "some what" good enough for my needs.
这是我在 github 上所做的示例的链接.
Here's a link to an example of what i did on github.
基本上,我决定放弃分别加载2个根组件并动态加载这些组件的想法.
Basically I decided to drop the idea of having loading 2 root component separately and load the components dynamically.
如果有任何需要改进的地方,请告诉我.
If there's any area of improvements can be done please do let me know.
这篇关于Angular 2如何分别加载2 App根组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!