2016-09-02 42 views
16

Khi tôi biên dịch ứng dụng của tôi với tsc tôi nhận được TS2345 lỗi này:Angular2 nguyên cảo Chỉ thị lỗi 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'. 

Và đây là mã của tôi:

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>; 
} 

tôi không thấy bất cứ điều gì sai trong tôi mã, nó cũng được sử dụng để làm việc. Bất cứ ai có thể thấy những gì sai với điều này?

Lưu ý: Tôi đang sử dụng Angular2-RC6 và nguyên cảo 1.8.10, hy vọng những thông tin giúp

+0

Tôi đang thử nghiệm điều tương tự ở đây. Tìm kiếm một sửa chữa. – Tom

Trả lời

25

directives đã phản đối và loại bỏ. TimeTimeline nên đi trong @NgModule tờ khai của bạn bây giờ:

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

Tôi đã làm điều này, và tôi vẫn nhận được lỗi = (Bất cứ điều gì khác để thử? –

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 { 

} 
Các vấn đề liên quan