angular-cn/packages/core/src/linker
Alex Rickabaugh c61df39323 feat(router): deprecate loadChildren:string (#30073)
The proposed ES dynamic import() is now supported by the Angular CLI and the
larger toolchain. This renders the `loadChildren: string` API largely
redundant, as import() is far more natural, is less error-prone, and is
standards compliant. This commit deprecates the `string` form of
`loadChildren` in favor of dynamic import().

DEPRECATION:

When defining lazy-loaded route, Angular previously offered two options for
configuring the module to be loaded, both via the `loadChildren` parameter
of the route. Most Angular developers are familiar withthe `string` form of
this API. For example, the following route definition configures Angular to
load a `LazyModule` NgModule from `lazy-route/lazy.module.ts`:

```
[{
  path: 'lazy',
  loadChildren: 'lazy-route/lazy.module#LazyModule',
}]
```

This "magic string" configuration was previously necessary as there was
no dynamic module loading standard on the web. This has changed with the
pending standardization of dynamic `import()` expressions, which are now
supported in the Angular CLI and in web tooling in general. `import()`
offers a more natural and robust solution to dynamic module loading. The
above example can be rewritten to use dynamic `import()`:

```
[{
  path: 'lazy',
  loadChildren: () => import('./lazy-route/lazy.module').then(mod => mod.LazyModule),
}]
```

This form of lazy loading offers significant advantages in terms of:

* type checking via TypeScript
* simplicity of generated code
* future potential to run natively in supporting browsers
  (see: [caniuse: dynamic import()](https://caniuse.com/#feat=es6-module-dynamic-import))

As a result, Angular is deprecating the `loadChildren: string` syntax in
favor of ES dynamic `import()`. An automatic migration will run during
`ng upgrade` to convert your existing Angular code to the new syntax.

PR Close #30073
2019-04-24 17:06:05 -07:00
..
compiler.ts fix(ivy): properly compile NgModules with forward referenced types (#29198) 2019-03-12 18:26:42 -07:00
component_factory.ts build: extract interface and util sub compilation from core (#28028) 2019-01-10 16:31:44 -08:00
component_factory_resolver.ts build: extract interface and util sub compilation from core (#28028) 2019-01-10 16:31:44 -08:00
element_ref.ts fix(core): proper @internal and @nocollapse combined usage fix (#28138) 2019-01-14 14:33:09 -08:00
ng_module_factory.ts build: extract interface and util sub compilation from core (#28028) 2019-01-10 16:31:44 -08:00
ng_module_factory_loader.ts feat(router): deprecate loadChildren:string (#30073) 2019-04-24 17:06:05 -07:00
query_list.ts refactor(ivy): remove duplicated flatten util (#29547) 2019-03-27 12:36:23 -07:00
system_js_ng_module_factory_loader.ts feat(router): deprecate loadChildren:string (#30073) 2019-04-24 17:06:05 -07:00
template_ref.ts docs: add api doc to template_ref (#27380) 2019-01-22 12:13:50 -08:00
view_container_ref.ts fix(core): proper @internal and @nocollapse combined usage fix (#28138) 2019-01-14 14:33:09 -08:00
view_ref.ts docs: update core to use `@publicApi` tags (#26595) 2018-10-19 14:35:53 -07:00