I'm looking to pull in data from an XML file and use that as the starting values for my in-memory web API in Angular 7:
My app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { HttpClientModule } from '@angular/common/http';
import { NgModule } from '@angular/core';
import { HttpClientInMemoryWebApiModule } from 'angular-in-memory-web-api';
import { AppRoutingModule } from './app-routing.module';
import { HomeComponent } from './pages/home/home.component';
import { InMemoryDataService } from './app.database';
@NgModule({
declarations: [HomeComponent],
imports: [
BrowserModule,
AppRoutingModule,
HttpClientModule,
HttpClientInMemoryWebApiModule.forRoot(
InMemoryDataService, { dataEncapsulation: false }
)
],
providers: [],
bootstrap: [HomeComponent]
})
export class AppModule {}
The database is being created in a file called app.database.ts, found in /src/app (same place as app.module.ts
import { InMemoryDbService } from 'angular-in-memory-web-api';
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class InMemoryDataService implements InMemoryDbService {
constructor() {}
createDb() {
return {
products: []
};
}
}
I am currently stuck on how to implement the database. Specifically, I have the following questions:
- Which side will be the best place to put the database file. Assuming it's called
database.xml? - How do I retrieve the database inside the
InMemoryDataServiceand subsequently create the in-memory database?
Any help provided is much appreciated