如何在内存 web api 中获取两个不同的 json
How to In memory web api for two different jsons
我正在使用 In memory web api 用于两个 json 服务 (DB)
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)]
中添加两个数据库
我收到 StudentData 服务的 404 错误。如果我从中删除一个 dbService,它工作正常
我的疑问是如何在forRoot方法中添加两个dbservices?
您可以对两者使用一种服务,并且return两者都使用集合名称和解决方案。
这里是 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};
}
}
app 模块就是这样
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/heroes" && "/api/students".
我正在使用 In memory web api 用于两个 json 服务 (DB)
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)]
我收到 StudentData 服务的 404 错误。如果我从中删除一个 dbService,它工作正常
我的疑问是如何在forRoot方法中添加两个dbservices?
您可以对两者使用一种服务,并且return两者都使用集合名称和解决方案。
这里是 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};
}
}
app 模块就是这样
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/heroes" && "/api/students".