没有路由器或导入或loadChildren的组件的角延迟加载 [英] angular lazy loading of component without router or import or loadChildren
问题描述
是否有一种方法可以像<my-component></my-component>
那样直接从html中的标记中直接延迟加载组件?
Is there a way in angular to lazy load component directly from the tag in html like <my-component></my-component>
?
在组件模板解析期间,angular应在发现任何无法在html中使用或尚未加载的新标签时将整个组件加载到浏览器中.
during component template parsing, angular should load the entire component into the browser when it finds any new tag which is not available in html or not already loaded.
我知道我们可以使用loadChildren
加载模块,该模块仅特定于路由,并且还需要加载模块及其组件.我只搜索组件,而直接搜索组件,而不是模块.
I know we can load a module using loadChildren
which is only specific to routing and also need to load the module and its component. I am searching only for component and directly the component not the module.
我不想使用路由器或不想在应用程序中导入组件ot模块.我想当angular2找到不在html5中的标记时,它将在一个spcictfic文件夹中搜索并加载js和html文件,并将该组件注入特定的标记中
I dont want to use router or dont want to import the component ot module in my application. I want when angular2 will find a tag which is not in html5 it will search in a spcictfic folder and load the js and html file and inject that component in the specific tag
推荐答案
在您的情况下,您必须对组件生成器使用动态组件加载,而该组件生成器受AOT的限制,因此动态组件将无法使用AOT.
In your case you have to use dynamic component loading with component builder, which has limitation with AOT, Dynamic component will not work with AOT.
动态组件加载将找到您的标签并在DOM中加载适当的组件
Dynamic component loading will find your tag and load appropriate component in DOM
这篇关于没有路由器或导入或loadChildren的组件的角延迟加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!