angular - 在 Angular 7 中将数据解析为 in-memory-web-api
问题描述
我希望从 XML 文件中提取数据并将其用作 Angular 7 中我的内存中 Web API 的起始值:
我的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 {}
数据库正在一个名为 的文件中创建,该文件app.database.ts
位于/src/app
(与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: []
};
}
}
我目前被困在如何实现数据库上。具体来说,我有以下问题:
- 哪一侧是放置数据库文件的最佳位置。假设它被称为
database.xml
? - 如何检索内部数据库
InMemoryDataService
并随后创建内存数据库?
非常感谢提供的任何帮助
解决方案
推荐阅读
- c++ - 尝试添加外部库时出现 CMake 错误
- ios - 如何建立一个iOS快捷方式来打开几个网页?
- python - 涉及类的递归函数
- linux - Apache2 000-Default VHost 不会被请求选择
- java - 如何从 ObjectInputStream 中读取所有对象
- authentication - WebAPI如何从管理员禁用另一个用户
- ios - Xamarin.form 键盘出现时上移视图
- c++ - C++,将两个参数包传递给构造函数
- ios - 如何将我的 UIImageView 内容保存到我的画廊?(迅速)
- google-chrome - 无法读取未定义的属性“onBoundsChanged”