Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

loadChildren syntax - what is hash part

Angular in the docs says the following:

{
  path: 'admin',
  loadChildren: 'app/admin/admin.module#AdminModule',
},

I'm curious about the syntax. As I understand, this part:

app/admin/admin.module

defines the path to load a module. But what is this #AdminModule?

I'm reading this article, and there is the following path:

loadChildren: 'contacts.bundle.js',

so, as you can see, there is nothing with hash.

like image 302
Max Koretskyi Avatar asked Jan 17 '17 12:01

Max Koretskyi


1 Answers

The hash part denotes the exported module name. So, inside app/admin/admin.module the AdminModule is exported:

export class AdminModule {}

However, if default export is used, there is no need to use hash.

Here is the relevant part from the sources system_js_ng_module_factory_loader.ts:

  private loadAndCompile(path: string): Promise<NgModuleFactory<any>> {
    let [module, exportName] = path.split(_SEPARATOR);
    if (exportName === undefined) exportName = 'default';

    return System.import(module)
        .then((module: any) => module[exportName])
        .then((type: any) => checkNotEmpty(type, module, exportName))
        .then((type: any) => this._compiler.compileModuleAsync(type));
  }
like image 164
Max Koretskyi Avatar answered Oct 16 '22 17:10

Max Koretskyi