我正在开发一个Angular2应用程序,我有以下组件:
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 :(得分:2)
事实证明,无论何时我想修改添加新属性甚至创建新界面的界面,我都必须停止ng serve
命令并重新运行它。