I am trying to use angular2-in-memory-web-api in my angular 2 project. I'm having trouble finding any documentation that shows how to return different data objects for different requests with the same collection name. I believe the class I use for my SEED_DATA is off but I'm not sure how to structure it the right way to get what I want.
Here is my main.ts
import {provide} from "@angular/core";
import {bootstrap} from "@angular/platform-browser-dynamic";
import {HTTP_PROVIDERS, XHRBackend} from "@angular/http";
import {AppComponent} from "./app.component";
import {SEED_DATA, InMemoryBackendService} from "angular2-in-memory-web-api/in-memory-backend.service";
import {AppTestData} from "./AppTestData";
bootstrap(AppComponent, [
HTTP_PROVIDERS,
provide(XHRBackend, {useClass: InMemoryBackendService}),
provide(SEED_DATA, {useClass: AppTestData})
]);
My AppTestData.ts file would look something like this
export class AppTestData {
createDb() {
let studentData = {
name: "Student Name",
grade: "B"
};
let otherStudentData = {
name: "Other Student Name",
grade: "A"
};
let httpPaths = {
somepath: {
student: studentData,
anotherPath: {
student: otherStudentData
}
}
}
return httpPaths;
}
}
My attempt at the httpPaths object is off. But the idea would be me calling a get http call to "something/student" and getting back studentData and calling another get http call to "something/anotherPath/student" and getting back otherStudentData.
The following does seem to work but I would like to specify my complete path incase I want post to “something/student” and “something/anotherPath/student” and get different results.
let httpPaths = {
student: studentData
}
I believe you missed the brackets in the return statement:
return {httpPaths};
The developer created an example which can be found here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With