在Angular2 RC4中,如何将组件添加到预编译数组?

Jee*_*gee 21 router angular

我刚刚将Angular2项目更新为RC4,当我打开应用程序时,路由器现在在控制台中发出此警告消息:

router.umd.js:2466 'FrontpageComponent' not found in precompile array.  To ensure all components referred to by the RouterConfig are compiled, you must add 'FrontpageComponent' to the 'precompile' array of your application component. This will be required in a future release of the router.
Run Code Online (Sandbox Code Playgroud)

我试图找出我需要做些什么来解决这个问题,但由于文档很少,我找不到答案.什么是这个预编译数组,我在哪里可以找到它或如何添加它?

Gün*_*uer 22

在较新的路由器版本中,这不再是必需的.

<= RC.4

它只是@Component()@Directive()装饰器的附加参数:

@Component({
  selector: '...',
  template: '...',
  directives: [FrontpageComponent],
  precompile: [FrontpageCmponent]
})
Run Code Online (Sandbox Code Playgroud)

https://github.com/angular/angular/blob/6c5b653593eff19c5b9342b2cf0195aca49379cb/modules/%40angular/core/src/metadata/directives.ts#L968

/**
*定义
*此组件定义时应预编译的组件.对于此处列出的每个组件,
*Angular将创建一个{@link ComponentFactory ComponentFactory}并将其存储在
*{@link ComponentFactoryResolver ComponentFactoryResolver}中.

  • 我在3.0.0-beta.1中看到了这一点,但在升级到3.0.0-beta.2之后,我在控制台日志中看不到任何警告. (7认同)