我们可以在当前版本的Angular2中使用另一个组件内的组件吗?

Pan*_*ale 1 angular2-template angular

我想在angular2当前版本(V2.2.0)中使用另一个组件内的组件

但之前我们可以选择使用以下代码在另一个组件中使用组件.

import { AnotherComponent } from './another-component';

@Component({
  selector: 'my-component',
  directives: [AnotherComponent],
  template: '<div>Something there<another></another></div>'
})
export class OtherComponent {
}
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试相同它不起作用时,它会抛出模板编译错误.

此功能现已删除吗?或者有另一种方法可以做同样的事情吗?

错误信息

  1. 如果'navigation'是Angular组件,则验证它是否是此模块的一部分.
  2. 如果'navigation'是Web组件,则将"CUSTOM_ELEMENTS_SCHEMA"添加到此组件的'@NgModule.schemas'以禁止显示此消息.("

mue*_*ich 5

您必须在声明中添加AnotherComponent模块

declarations: [
  AnotherComponent 
]
Run Code Online (Sandbox Code Playgroud)