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
屬性確實是接口的一部分。那麼有人能告訴我這裏有什麼問題嗎?
你是否將ts文件編譯爲js文件? – echonax
'courseAdminService.get'函數的返回值是什麼。如果那不會返回課程,他可以抱怨。但它會很好地知道他認爲這發生的行號 – Daniel
@echonax我使用從nglar-cli的'ng serve'命令,它會自動執行此操作 – m2008m1033m