Angular 2错误(类型"Component"中不存在“指令") [英] Angular 2 Error ( 'directives' does not exist in type 'Component' )

查看:69
本文介绍了Angular 2错误(类型"Component"中不存在“指令")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am beginner in Angular 2 and I'm using the final Angular 2 release version. I have a strange problem with it. this is my databinding.component.ts code:

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]
})

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

and this is a peace of my app.module.ts code :

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

@NgModule({
  declarations: [
    AppComponent,
    OtherComponent,
    AnotherComponent,
    DatabindingComponent,
    PropertyBindingComponent,
    EventBindingComponent
  ]

此代码无法正常工作:

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'.

我该怎么办?!?!

推荐答案

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

directives was removed from component. See the following: https://stackoverflow.com/a/39410642/5487673

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

The solution to the problem is simply to remove the directives attribute from your component. So long as the components listed under your directives attribute are declared at the NgModule level then you should be right.

这篇关于Angular 2错误(类型"Component"中不存在“指令")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆