问题描述
我是 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 代码:
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
属性.只要您的 directives
属性下列出的组件是在 NgModule
级别声明的,那么您应该是对的.
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 错误(“组件"类型中不存在“指令")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!