简体   繁体   中英

Load module components dynamically Angular2

Basically there is a module.ts in every created module of the app for example:

ng generate module newModuleName

then the module is created with the newModuleName.module.ts file

In the file, there is @NgModule with a declarations element.

So I want to dynamically modify the declarations array to prevent all components from being loaded in memory at the same time.

How can I do that?

If your goal is to prevent all of the components from being downloaded at one time on startup, you can use lazy loading.

Regarding memory, when a component is activated by routing to it or showing it as a child component, it is loaded in memory. As soon as the user navigates away from the page showing the component, the component is destroyed.

So you don't have to do anything in the declarations to make this happen.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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