Comments (9)
Oh sure, you can definitely do this. Each component has it's own injector, which is what resolves providers for itself and all components in that subtree.
Your second example should have worked:
@Component({
providers: [
{ provide: XHRBackend, useClass: InMemoryBackendService }, // in-mem server
{ provide: SEED_DATA, useClass: InMemoryDataService } // in-mem server data
]
})
As for that component and it's subtree, XHRBackend
is InMemoryBackendService
instead of the service provided by HTTP_PROVIDERS
.
Remember that it also applies to any other components in that subtree however. Maybe that's what was going wrong?
from in-memory-web-api.
It's not really designed for your scenario. It's a Dev and demo tool and we haven't tried to make it super robust.
It might be nice to add a config option that allows for pass-thru of unrecognized routes (we take PRs).
It is also possible (perhaps easy) to reprovide both in mem web api and http services at a component level and then both will be confined to that component and its sub tree.
from in-memory-web-api.
This feature will be very useful in case when you have established contract for new feature with api developers but they are behind you with time schedule.
That way you can start work independently on new feature which will use inMemory Api. Rest of App will use regular api.
Everyone is happy :) - especially project manager :D
from in-memory-web-api.
Yes, did meet my needs. I'm already using the passThruUnknownUrl
configuration and it is acting like I needed.
Thanks guys!
from in-memory-web-api.
I'm going to test this approach again. I think may be because the DI
strategy that I was using was wrong. I'll give you a reply ASAP. Thank you
very much!
from in-memory-web-api.
in RC5 this will perfectly fit into @NgModule scope :)
from in-memory-web-api.
I could not get things working by using it inside and child module called Analysis. What I did was import the InMemoryWebApiModule inside a child module and call the http.get from a child service that belongs to that child module.
Child Module
@NgModule({
...
imports: [
InMemoryWebApiModule.forRoot(AnalysisData) // in memory here
],
providers: [
AnalysisService // Service here
],
})
Child Service
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
@Injectable()
export class AnalysisService {
constructor(private http: Http){}
getAnalyses(){
return this.http.get('app/analysis').toPromise();
}
}
My route to this child module is:
{ path: 'analysis', component: AnalysisListComponent
And in my app.module I load the Analysis module
@NgModule({
bootstrap: [
...
],
declarations: [
...
],
imports: [
...
AnalysisModule, // loading the submodule here
Using this approach, when I reach the app/analysis the app return a 404 error. What am I doing wrong here? How can I reach the analysis in memory endpoint?
If I import the in memory module in the App module and call forRoot there, all of my http requests will pass through in memory service and that is not what I want. I want to use in memory only in a specific service, not even in a module scope, only in a service scope. and if its possible, only in a service method scope.
If you think it is better to use SO to find a solution for this, just say the word.
Thanks.
from in-memory-web-api.
@wardbell when you said "It is also possible (perhaps easy) to reprovide both in mem web api and http services at a component level and then both will be confined to that component and its sub tree." you are saing that it is already possible or it is only a tip?
I'll try to check your code more deeply to see if I come up with some idea and make a PR.
Feel free to close this issue or leave it open to see how much people need this feature and maybe to get some PR.
Thanks a lot for your help guys!
from in-memory-web-api.
See duplicate #30. I think PR #31 will meet your needs.
from in-memory-web-api.
Related Issues (20)
- It does not enable to use models who the id type is a string.
- parseUrl cannot handle URI's contain the `@` symbbol HOT 1
- Cannot handle multilevel URI's HOT 1
- r
- Imports broken or not working HOT 3
- Get creates object
- error: "Collection 'heroes' not found" HOT 1
- Unable to query using relative links
- Upgrade to v8 - Broken Peer Dependencies HOT 1
- Example of constructing responses in HTTP method interceptors + typings problem HOT 4
- Posting array
- Angular httpClient.put method not updating the data HOT 1
- When i delete the object it will delete the content but not delete the object. HOT 1
- Error after upgrading to Angular 9 - ModuleWithProviders requiring to explicitly specify generic type HOT 1
- Changelog for 0.10.0 HOT 1
- Angular 9.1.0 support HOT 2
- Migration to @ng-stack/api-mock HOT 2
- Once I build my angular application which uses in-memory-web-api and host it on a domain, would be in-memory-web-api still be able to function CRUD operations?
- post409 option in InMemoryBackEndConfigArgs labelled incorrectly
- post a new value for an array
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from in-memory-web-api.