Angular Elements/路由器插座 [英] Angular Elements / router outlet

查看:62
本文介绍了Angular Elements/路由器插座的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Angular Element可以使用路由器插座吗?

如果是的话,该路由器出口是否会干扰父路由器出口(与之交互)?

解决方案

否和是.

角度元素是为外部世界而设计的,而不是为内部角度应用而设计的.因此,如果您拥有CMS应用程序或某个大型应用程序,并且许多团队都在使用该应用程序,则他们会在其中发布代码,并且代码可能使用不同的语言,并且他们都应该在同一页面上一起工作.

因此,角度元素将导出自定义元素,该自定义元素将直接注入DOM并可以与他人对话.

现在回答您的问题.如果要动态加载组件,可以通过加载cheldren来做到这一点,它将加载代码并注入.

  {路径:数据实体",loadChildren:"app/somemodule/somemodule.module#myModule"} 

由于您的应用是有角度的,而您的组件也是有角度的,因此您可以在您的路线中直接使用它,在这种情况下,您也不需要使用自定义元素.

在您需要自定义元素的情况下,一个用例很强,另外一些则需要开发它,并且您想使用route路由到该组件.在这种情况下,您可以导入该角度模块并在您的项目中使用.

Angular团队可能会检查那里的测试用例,并查看是否需要将其用作执行此操作的选项,但到目前为止,尚无此功能.

Can an Angular Element use the router outlet?

And, if so, will that router outlet interfere with (interact with) the parent router outlet?

解决方案

No and yes at the same time.

Angular elements are designed for external world and not for the internal angular application. So if you have CMS application or some big application and many teams are working in the application they post there codes and it may be in different language and they all should work together in the same page.

So angular element exports custom element which will directly injected to DOM and can talk to others.

Now answer to your questions. If you want to load a component dynamically you can do that by loading cheldren and it will load the code and inject.

  {
    path: 'data-entities',
    loadChildren: 'app/somemodule/somemodule.module#myModule'
  }

As your app is angular and your component is also angular you can directly use that in your route, in this case also you don't need to use custom element.

One use case is strong where you need custom element is, some other develop it and you want to route to that component using route. in that case you can import that angular module and use in your project.

Angular team might review in there test cases and see more if they need to use it as an option to do it but as of now there is not available.

这篇关于Angular Elements/路由器插座的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆