javascript-在Angular 4.2.2 CLI Web-api中找不到angular-in-memory-web-api页面

我正在学习Angular框架(使用4.2.2版),并遵循教程“英雄之旅”.在HTTP部分中,该教程使用angular-in-memory-web-api来模拟Web api服务器,我尝试使用它,但是它不起作用.来自浏览器控制台的消息告诉我
  状态为:404找不到URL:api / heroes的响应
  我通过节点安装npm安装了angular-in-memory-web-api,我安装了angular-in-memory-web-api,这是我的代码(与教程相同)implement in-memory-web-api for api/heroes import module我从项目中错过了什么.

解决方法:

检查app / in-memory-data.service.ts,其中createDb()方法返回api端点.返回的对象使用ES6语法“对象解构”,该结构将heroes数组绑定到对象中的“ heroes”字段.

import { InMemoryDbService } from 'angular-in-memory-web-api';
export class InMemoryDataService implements InMemoryDbService {
  createDb() {
    const heroes = [
      { id: 0,  name: 'Zero' },
      { id: 11, name: 'Mr. Nice' },
      { id: 12, name: 'Narco' },
      { id: 13, name: 'Bombasto' },
      { id: 14, name: 'Celeritas' },
      { id: 15, name: 'Magneta' },
      { id: 16, name: 'RubberMan' },
      { id: 17, name: 'Dynama' },
      { id: 18, name: 'Dr IQ' },
      { id: 19, name: 'Magma' },
      { id: 20, name: 'Tornado' }
    ];
    return {heroes}; // !!!pay attention to this line; it creates api/heroes rest endpoint
  }
}

相关文章

ANGULAR.JS:NG-SELECTANDNG-OPTIONSPS:其实看英文文档比看中...
AngularJS中使用Chart.js制折线图与饼图实例  Chart.js 是...
IE浏览器兼容性后续前言 继续尝试解决IE浏览器兼容性问题,...
Angular实现下拉菜单多选写这篇文章时,引用文章地址如下:h...
在AngularJS应用中集成科大讯飞语音输入功能前言 根据项目...
Angular数据更新不及时问题探讨前言 在修复控制角标正确变...