我关注tutorial here,但修改为持有'Staff'实例而不是'Heroes'。似乎这个类破坏了我的代码 - 我得出了这个结论,好像我从app.module.ts的导入部分注释掉了行InMemoryWebApiModule.forRoot(InMemoryDataService),
,网页加载时没有InMemoryDataService所需的内容 - 谁能告诉我这堂课有什么问题?
在此之前,我使用的是一个常量数组的Staff,它被导出以保存数据(如教程指示的那样)。我的其余代码与修改处理“服务”对象而不是“英雄”对象的教程相同。
下面是InMemoryDataService类
import { InMemoryDbService } from 'angular-in-memory-web-api';
export class InMemoryDataService implements InMemoryDbService {
createDb() {
let staff = [
{ id: 11, firstName:'Jeremy', lastName:'Phan', email:'email', phone:444},
{ id: 12, firstName:'Jacob', lastName:'Phantom', email:'email', phone:444},
{ id: 13, firstName:'Yi', lastName:'Hi', email:'email', phone:444},
{ id: 14, firstName:'Steven', lastName:'Hawkings', email:'itguy@world.com', phone:1300655506},
{ id: 15, firstName:'Calvin', lastName:'Chan', email:'melbournestorm.calvinchan@gmail.com', phone:14355555532},
{ id: 16, firstName:'Cameron', lastName:'Tall', email:'melbournestorm.camerontall@gmail.com', phone:23452345},
{ id: 17, firstName:'Alex', lastName:'Flairdiddy', email:'melbournestorm.alexflair@gmail.com', phone:234523452}
];
return {staff};
}
}
员工班
export class Staff
{
id: number;
firstName: string;
lastName: string;
email: string;
phone: number;
}
干杯!