当我使用tsc编译我的应用程序时,我收到此错误TS2345:
error TS2345:
Argument of type '{ selector: string; template: string; directives: (typeof Title | any[])[]; providers: typeof Goo...' is not assignable to parameter of type 'ComponentMetadataType'.
这是我的代码:
import { Component, Input } from "@angular/core";
import { Title } from "./components/title";
import { Timeline } from "./components/timeline";
@Component({
selector: "edu",
template: `
<div id="Edu" class="Edu content section scrollspy">
<title [icon]="titleIcon" [title]="titleTitle"></title>
<timeline [data]="edu"></timeline>
</div>
`,
directives: [Title, Timeline]
})
export class Edu {
private titleIcon = "graduation-cap";
private titleTitle = "Education";
@Input("data") edu: Array<Object>;
}
我的代码中没有看到任何错误,也曾用过。任何人都可以看出这有什么问题吗?
注意:我正在使用Angular2-rc6和TypeScript 1.8.10,希望这些信息有帮助
答案 0 :(得分:26)
directives
已弃用并已删除。
Time
和Timeline
现在应该在您的@NgModule
声明中:
@NgModule({
declarations: [Time, Timeline, ...],
...
})
答案 1 :(得分:4)
#--------------app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { Time} from './Time.component'
import { Timeline} from './Timeline.component'
@NgModule({
imports: [ BrowserModule ],
declarations: [ AppComponent, TimeComponent, TimelineComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule { }
#--------------app.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
template: `<h1>{{title}}</h1>
<time></time>
<timeline></timeline>
`
})
export class AppComponent {
title = 'My Title';
}
#--------------time.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'time',
template: `<p>Do Something With Time Here</p>`
})
export class TimeComponent {
}
#--------------timeline.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'timeline',
template: `<p>Do Something With Timeline Here</p>`
})
export class TimelineComponent {
}