我正在使用 Angular 2 CLI,并使用ng generate component MyComponent
. 据我所知,我必须将组件添加到装饰器的指令键值对中@Component
,但此时打字稿编译失败,说:
ERROR in [default] /Users/Philip/Desktop/Angular2/src/app/app.component.ts:8:2
Argument of type '{ selector: string; template: any; styles: any[]; directives: typeof MyComponentComponent[]; }' is not assignable to parameter of type 'Component'.
Object literal may only specify known properties, and 'directives' does not exist in type 'Component'.
这是我的应用程序代码:
import { Component } from '@angular/core';
import { MyComponentComponent } from './my-component/my-component.component'
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
directives: [MyComponentComponent],
})
export class AppComponent {
title = 'app works!';
}
我没有接触生成组件的代码,但以防万一:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-my-component',
templateUrl: './my-component.component.html',
styleUrls: ['./my-component.component.css']
})
export class MyComponentComponent implements OnInit {
constructor() {
}
ngOnInit() {
}
}