如何在Angular2中使用angular内存web api?
我已经安装了这个软件包 我的模拟数据类:如何在Angular2中使用angular内存web api?,angular,angular2-services,angular-http,Angular,Angular2 Services,Angular Http,我已经安装了这个软件包 我的模拟数据类: import { InMemoryDbService } from 'angular-in-memory-web-api'; export class InCredentialsService implements InMemoryDbService { public createDb() { const credentials = { auth: true, id: 1, token: 'token
import { InMemoryDbService } from 'angular-in-memory-web-api';
export class InCredentialsService implements InMemoryDbService {
public createDb() {
const credentials = {
auth: true,
id: 1,
token: 'token',
grant: 'all'
};
return credentials;
}
}
在app.module.ts
中,我在import
部分中设置了相关性:
InMemoryWebApiModule.forRoot(InMemoryDataService)
现在我试着这样使用它:
return this.http.get('api/credentials');
它返回给我HTTP错误:
未找到URL:api/凭据的状态为404的响应
如何正确使用内存中的web api?使用
return { credentials };
这是
return { credentials: credentials };
标识符将成为API