angular / in-memory-web-api

The code for this project has moved to the angular/angular repo. This repo is now archived.
MIT License
1.18k stars 231 forks source link

HttpClientInMemoryWebApiModule has http-backend.service dependency #215

Open pauleustice opened 5 years ago

pauleustice commented 5 years ago

Hi, I've just tried using this module for the first time and ran into this issue:

Version: 0.6.1 Angular Version: 6

When trying to build, I receive this Typescript error, failing the build:

ERROR in node_modules/angular-in-memory-web-api/http-backend.service.d.ts(2,75): error TS2307: Cannot find module '@angular/http'

App module (cut down for brevity):

import { HttpClientInMemoryWebApiModule } from 'angular-in-memory-web-api';
import { MockApiService } from './services/mock-api.service';

@NgModule({
  declarations: [ AppComponent ],
  imports: [
    BrowserModule,
    HttpClientModule,
    environment.production ?
      [] : HttpClientInMemoryWebApiModule.forRoot(
      MockApiService, {
        dataEncapsulation: false,
        passThruUnknownUrl: false,
        put204: false // return entity after PUT/update
      }
    ),
  ]

MockApiService:

import { InMemoryDbService } from 'angular-in-memory-web-api';

export class MockApiService implements InMemoryDbService {
  createDb() {
    const reports = [
      { id: 1, limit: 37},
      { id: 2, limit: 118 },
      { id: 3, limit: 93 },
    ];
    return {
      reports
    };
  }
}

As far as I can tell, if one is using the HttpClientInMemoryWebApiModule, there should be no dependencies on @angular/http. It's a simple fix to npm i it, but seems like a bug nonetheless.

SamJBarney commented 5 years ago

I am running on Angular 7, and am having the same problem. It seems like a small problem that a lot of new Angular people run into, and so if you're gonna keep the backwards compatibility, you should at least update the docs to explain to people how to resolve the issue.

BStephenBB commented 5 years ago

Just got the same error while going through the Angular docs for the first time too. Definitely confusing.

hieundx commented 5 years ago

@angular/httpAPI is deprecated in favor of @angular/common/http. But changing the import source to @angular/common/httpwon't solve it bc the API doesn't export those in @angular/http https://angular.io/api/http

robsoncloud commented 5 years ago

same here

ghost commented 5 years ago

Doing an Angular 7 project and I too am facing this issue. An ugly way of temporarily fixing it is to npm install @angular/http --save-dev @wardbell should have a serious look into this.

vishal423 commented 5 years ago

I see many duplicate issues opened for same reason. Please do note a PR is already in progress to remove this dependency #223

JudeMag commented 5 years ago

Hey Guys, give this a try npm install angular-in-memory-web-api --save

KostyaTretyak commented 5 years ago
npm r angular-in-memory-web-api
npm i -D angular-in-memory-web-api
SuperITMan commented 5 years ago

Hey everyone, For your info the issue has been solved with version 0.8.0: https://github.com/angular/in-memory-web-api/blob/master/CHANGELOG.md#080-2018-12-06 😊