简体   繁体   English

Angular2中指令的替代是什么?

[英]What's the replacement of Directive in Angular2?

I've been learning Angular2. 我一直在学习Angular2。 I observed that 'directive' tag was used inside @Component metadata in RC version to refer another component in it. 我观察到在RC版本的@Component元数据中使用了“ directive”标记来引用其中的另一个组件。 But there is no 'directive' tag associated with it in Ang version 2.1.0. 但是在Ang版本2.1.0中没有与之关联的“指令”标记。 how am I supposed to refer another component now? 我现在应该如何引用另一个组件?

You should declare directives in declarations meta property of @NgModule as shown below (as directives meta property has been removed from @Component decorator) 您应该在@NgModule declarations meta属性中声明directives ,如下所示(因为directives meta属性已从@Component装饰器中删除)

@NgModule({
  imports      : [ BrowserModule, .... ],
  declarations : [
    AppComponent,
    DashboardComponent    //<<<### here it is another component or directive,
    HighlightDirective    //<<<### directive declared with @Directive decorator
  ],
  providers    : [  ],
  bootstrap    : [ AppComponent ]
})

export class AppModule { }

for more information you can refer to https://angular.io/docs/ts/latest/guide/ngmodule.html 有关更多信息,请参阅https://angular.io/docs/ts/latest/guide/ngmodule.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM