我正在为两个json服务(DB)使用内存web api。
1)
import {InMemoryDbService} from 'angular-in-memory-web-api';
export class InMemoryDataService implements InMemoryDbService {
createDb() {
let heroes = [
{id: 11, name: 'Mr. Nice'},
{id: 12, name: 'Narco'},
{id: 13, name: 'Bombasto'},
{id: 14, name: 'Celeritas'},
{id: 15, name: 'Magneta'},
{id: 16, name: 'RubberMan'},
{id: 17, name: 'Dynama'},
{id: 18, name: 'Dr IQ'},
{id: 19, name: 'Magma'},
{id: 20, name: 'Tornado'}
];
return {heroes};
}
} 2)
import {InMemoryDbService} from 'angular-in-memory-web-api';
import {Address} from "cluster";
export class StudentData implements InMemoryDbService {
createDb() {
let students = [
{
id: 11,
FirstName: 'Mounika',
LastName: 'Gangamwar',
email: 'asa@gmailc.com',
Phonenumber: 1111,
Address: '2323',
Password: 'asa',
CPassword: 'aa'
}
];
return {students};
}
}我的app.module.js是
import {InMemoryWebApiModule} from 'angular-in-memory-web-api';
import {InMemoryDataService} from './in-memory-data.service';
import {StudentData} from './forms/student.data.service';
@
NgModule({
imports: [
BrowserModule,
FormsModule,
InMemoryWebApiModule.forRoot(InMemoryDataService, StudentData)
],
declarations: [AppComponent],
bootstrap: [UIView]
})我的问题是我不能在InMemoryWebApiModule.forRoot(InMemoryDataService,StudentData)]中添加两个db
我收到了StudentData服务的404个错误。如果我把一个dbService从里面去掉,它就能正常工作了
我怀疑如何将两个dbservices添加到forRoot方法中?
发布于 2019-03-25 11:54:40
您可以对两者使用一个服务,并以解决方案集合的名称返回这两个服务。
这是InMemoryDataService
import {InMemoryDbService} from 'angular-in-memory-web-api';
export class InMemoryDataService implements InMemoryDbService {
createDb() {
let heroes = [
{id: 11, name: 'Mr. Nice'},
{id: 12, name: 'Narco'},
{id: 13, name: 'Bombasto'},
{id: 14, name: 'Celeritas'},
{id: 15, name: 'Magneta'},
{id: 16, name: 'RubberMan'},
{id: 17, name: 'Dynama'},
{id: 18, name: 'Dr IQ'},
{id: 19, name: 'Magma'},
{id: 20, name: 'Tornado'}
];
let students = [
{
id: 11,
FirstName: 'Mounika',
LastName: 'Gangamwar',
email: 'asa@gmailc.com',
Phonenumber: 1111,
Address: '2323',
Password: 'asa',
CPassword: 'aa'
}
];
return {heroes, students};
}
}应用程序模块就是这样
import {InMemoryWebApiModule} from 'angular-in-memory-web-api';
import {InMemoryDataService} from './in-memory-data.service';
@NgModule({
imports: [
BrowserModule,
FormsModule,
InMemoryWebApiModule.forRoot(InMemoryDataService, {apiBase: '/api'})
],
declarations: [AppComponent],
bootstrap: [UIView]
})并且将根据每个学生和英雄的URL生成集合名称& "/api/ students“。
https://stackoverflow.com/questions/41458040
复制相似问题