I have a lot of modules and want to sort and split it by several arrays by types
const aModules: any[] = [
Module1,
Module2,
Module3,
Module4
];
const bModules: any[] = [
Module5,
Module6,
Module7,
Module8
]
It will works if use a spread operator
imports: [Module0, ...aModules, ...bModules]
But it not works if use a concat method, any components will not works if use next approach:
imports: [Module0].concat(aModules, bModules)
What difference for typescript compiler for this both methods? Cause if we see
console.log([Module0, ...aModules, ...bModules]);
console.log([Module0].concat(aModules, bModules));
Both results looks the same
@NgModule takes a metadata object that describes how to compile a component's template and how to create an injector at runtime. It identifies the module's own components, directives, and pipes, making some of them public, through the exports property, so that external components can use them.
BrowserModule and CommonModule link BrowserModule imports CommonModule , which contributes many common directives such as ngIf and ngFor . Additionally, BrowserModule re-exports CommonModule making all of its directives available to any module that imports BrowserModule .
Should I import BrowserModule or CommonModule ? link. The root application module, AppModule , of almost every browser application should import BrowserModule from @angular/platform-browser . BrowserModule provides services that are essential to launch and run a browser application.
It's difficult to answer this question, because this aspect of the Angular compiler doesn't have much documentation. Under the hood the AOT compiler rewrites a lot of the metadata used by the decorators, and I would suspect this is an example of something it can not transform correctly.
I can tell you that this has nothing to do with TypeScript or JavaScript. It is a problem with the AOT compiler.
You can read about transformers in this blog:
https://blog.angularindepth.com/do-you-know-how-angular-transforms-your-code-7943b9d32829
You can find the source code to the transformers here:
https://github.com/angular/angular/tree/master/packages/compiler-cli/src/transformers
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With