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 230 forks source link

Doesn't work when loaded from a lazy loaded module #210

Open jeandat opened 6 years ago

jeandat commented 6 years ago

I created a small repo to reproduce the situation. According to documentation, it is possible to use in-memory-web-api in a lazy loaded module. I might be misunderstanding something.

Also, I'm wondering, is it possible to declare several mock services in several modules or do you need to declare everything inside one service.

Thanks.

lazy.zip

wardbell commented 6 years ago

It wasn't intended to be loaded as a feature any more than HttpClient is intended to be loaded anywhere other than at the root.

But it should work IF AND ONLY IF you re-import HttpClient into the lazy feature module at the SAME TIME and SAME PLACE that you import this in-mem module.

Try it.

jeandat commented 6 years ago

Correct me if i'm wrong, but if I'm using http interceptors, it would be bad for me to import again HttpClientModule in my lazy feature module? My interceptor would not be invoked anymore, right?

ankemp commented 5 years ago

@jdat82, you are not wrong. Currently working through this problem now. Any suggestions/what path did you go with?

The only path I can see is to import all my in-mem services into my core module, which would not be ideal.

jeandat commented 5 years ago

Yes, that's what I did too. That's not ideal but there is no better solution for now.

taigi100 commented 4 years ago

I have the same issue. I need the InMemoryService just inside a few feature modules. I don't importing HttpClientModule again so I did. Still doesn't work even if I have it imported again. I did check the order and it is good. The InMemoryService does not get instantiated in my case - the createDB() method never gets called. Any clue what might be causing this?