2016-09-02 11 views
16

私はTSCと私のアプリをコンパイルするとき、私はこのエラーTS2345を取得:Angular2活字体ディレクティブエラー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を使用し、活字体1.8.10だが、これらの情報は

+0

。修正を探しています。 – Tom

答えて

25

directivesは廃止し、削除されたのに役立ちます願っています。 TimeTimelineは今、あなたの@NgModule宣言で行く必要があります。私はここに同じことを試してい

@NgModule({ 
    declarations: [Time, Timeline, ...], 
    ... 
}) 
+0

私はこれをして、まだエラーを取得しています=(他に何か試してみませんか? –

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 { 

}