首页 > 解决方案 > 在 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: []
        };
    }
}

我目前被困在如何实现数据库上。具体来说,我有以下问题:

非常感谢提供的任何帮助

标签: angularxml-parsingangular7angular-in-memory-web-api

解决方案


推荐阅读