角度2错误("指令"在"组件"类型中不存在)

Mah*_* Ta 9 data-binding components typescript angular

我是Angular 2的初学者,我正在使用最终的Angular 2发行版.我有一个奇怪的问题.这是我的databinding.component.ts代码:

import { Component } from '@angular/core';

import {PropertyBindingComponent} from './property-binding.component';
import {EventBindingComponent} from './event-binding.component';


@Component({
  selector: 'fa-databinding',
  templateUrl: 'databinding.component.html',
  styleUrls: ['databinding.component.css'],
  directives: [PropertyBindingComponent, EventBindingComponent]
})
Run Code Online (Sandbox Code Playgroud)

这是我的app.module.ts代码的和平:

import { PropertyBindingComponent } from './databinding/property-binding.component';
import { EventBindingComponent } from './databinding/event-binding.component';

@NgModule({
  declarations: [
    AppComponent,
    OtherComponent,
    AnotherComponent,
    DatabindingComponent,
    PropertyBindingComponent,
    EventBindingComponent
  ]
Run Code Online (Sandbox Code Playgroud)

此代码无法正常工作:

ERROR in [default] /home/tornado/work/first-app/src/app/databinding/databinding.component.ts:11:2 
Argument of type '{ selector: string; template: any; styles: any[]; directives: (typeof PropertyBindingComponent | ...' is not assignable to parameter of type 'Component'.
  Object literal may only specify known properties, and 'directives' does not exist in type 'Component'.
Run Code Online (Sandbox Code Playgroud)

我该怎么办?!?!

Sim*_*n K 15

directives已从组件中删除.请参阅以下内容:https://stackoverflow.com/a/39410642/5487673

解决问题的方法就是directives从组件中删除属性.只要您的directives属性下列出的组件在该NgModule级别声明,那么您应该是正确的.