创建模拟库,需要 继承InMemoryDbService接口, 创建一个服务“in-memory-data.service.ts” import{InMemoryDbService}from'angular-in-memory-web-api';exportclassInMemoryDataServiceimplementsInMemoryDbService{createDb(){consta=[];constb=[];return{a,b}}} 这里的写法a、b是模拟多个数据集合。 在根模块里导...
但是,如果我从“@angular/*中删除此路径,“我不会得到任何错误,但我测试库的模拟数据不会加载。我用InMemoryDataService创建了这个模拟数据,它实现了InMemoryDbService创建数据库。 package.json: { "name": "widgets-app", "version": "0.0.0", "license": "MIT", "scripts": { "ng": "ng", "start...
npm install --save angular-in-memory-web-api 构建数据模型 在todo文件夹创建文件todo-data.ts + View Code 我们创建了一个InMemoryDbService的内存数据库 内存web服务 首先在app.module.ts加入类引用 之前这里的angular-in-memory-web-api总是报错@angular/common/http找不到,原来是我的版本太高了(难道是不...
创建一个类 src/app/in-memory-data.service.ts import{InMemoryDbService}from'angular-in-memory-web-api';exportclassInMemoryDataServiceimplementsInMemoryDbService{createDb(){constheroes=[{id:11,name:'Mr. Nice'},{id:12,name:'Narco'},{id:13,name:'Bombasto'},{id:14,name:'Celeritas'},{id:...
3 ### 创建InMemoryData组件, 通过服务提供数据 ng generate service InMemoryData import{Injectable}from'@angular/core';import{InMemoryDbService}from'angular-in-memory-web-api';import{Hero}from'./hero'; @Injectable({providedIn:'root', })exportclassInMemoryDataServiceimplementsInMemoryDbService{createDb...
import { InMemoryDbService } from 'angular-in-memory-web-api'; export class InMemHeroService implements InMemoryDbService { createDb() { let heroes = [ { id: '1', name: 'Windstorm' }, { id: '2', name: 'Bombasto' }, { id: '3', name: 'Magneta' }, ...
之前测试时用的app/mock/user_data_memory_mock.ts数据 import{User}from'../model/User';import{InMemoryDbService}from'angular-in-memory-web-api';exportclassUserDataMemoryMockimplementsInMemoryDbService{createDb() {constusers:User[] = [newUser('chenjianhua_a',21,'2290910211@qq.com','123456'),ne...
An in-memory web api for Angular demos and tests readme Angular The sources for this package are in the main Angular repo. Please file issues and pull requests against that repo. Usage information and reference details can be found in Angular documentation. License: MITchangelog...
* with class that implements InMemoryDbService and creates an in-memory database. * * Usually imported in the root application module. * Can import in a lazy feature module too, which will shadow modules loaded earlier * * @param {Type} dbCreator - Class that creates seed data for in-...
{ InMemoryWebApiModule } from 'angular-in-memory-web-api';import { InMemoryTodoDbService } from './todo/todo-data';import { AppComponent } from './app.component';import { LoginComponent } from './login/login.component';import { AuthService } from './core/auth.service';import { ...