2017-04-04 63 views
1

我開發一個應用程序Angular2和我有以下組成部分:Angular2住宅「XXX」的類型不存在「XXX」

import {Component, OnInit} from '@angular/core'; 
import {CourseAdminService} from "../shared/course-admin.service"; 
import {Course} from "../shared/course"; 

@Component({ 
    selector: 'app-course-admin-list', 
    templateUrl: './course-admin-list.component.html', 
    styleUrls: ['./course-admin-list.component.css'] 
}) 
export class CourseAdminListComponent implements OnInit { 

    courses: Course[] = []; 
    keyword = ""; 

    constructor(private courseAdminService: CourseAdminService) { 
    } 

    ngOnInit() { 
    this.loadMore(); 
    } 

    reset() { 
    this.courses = []; 
    this.loadMore(); 
    } 

    loadMore() { 
    let since: Date = null; 
    let before: Date = null; 

    let len = this.courses.length; 
    if (len > 1000) { 
     since = this.courses[0].creationTime; 
     before = this.courses[len - 1].creationTime; 
    } 

    let subscription = this.courseAdminService.get(since, before, this.keyword) 
     .subscribe(courses => { 
     this.courses = this.courses.concat(courses); 
     subscription.unsubscribe(); 
     }); 
    } 
} 

而且我有以下接口:

export interface Course { 
    id: string; 
    nameEn: string; 
    nameAr: string; 
    trainer: string; 
    type: string; 
    country: string; 
    city: string; 
    level: string; 
    creationTime: Date; 
} 

這裏的問題是,當我嘗試編譯應用程序(使用angular @ cli)時,它給了我錯誤:Property 'creationTime' does not exist on type 'Course',正如你所看到的,creationTime屬性確實是接口的一部分。那麼有人能告訴我這裏有什麼問題嗎?

+0

你是否將ts文件編譯爲js文件? – echonax

+0

'courseAdminService.get'函數的返回值是什麼。如果那不會返回課程,他可以抱怨。但它會很好地知道他認爲這發生的行號 – Daniel

+0

@echonax我使用從nglar-cli的'ng serve'命令,它會自動執行此操作 – m2008m1033m

回答

1

事實證明,無論何時我想修改一個接口,如添加一個新屬性,甚至創建一個新接口,我都必須停止ng serve命令並重新運行一次。

相關問題