Giter VIP home page Giter VIP logo

Comments (9)

filipesilva avatar filipesilva commented on August 20, 2024 1

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.

wardbell avatar wardbell commented on August 20, 2024 1

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.

vukasin-nikodijevic avatar vukasin-nikodijevic commented on August 20, 2024 1

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.

vinagreti avatar vinagreti commented on August 20, 2024 1

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.

vinagreti avatar vinagreti commented on August 20, 2024

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.

vukasin-nikodijevic avatar vukasin-nikodijevic commented on August 20, 2024

in RC5 this will perfectly fit into @NgModule scope :)

from in-memory-web-api.

vinagreti avatar vinagreti commented on August 20, 2024

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.

vinagreti avatar vinagreti commented on August 20, 2024

@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.

wardbell avatar wardbell commented on August 20, 2024

See duplicate #30. I think PR #31 will meet your needs.

from in-memory-web-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.