AngularJS 2 : Getting data from json file not working

后端 未结 1 802
北恋
北恋 2020-12-06 14:03

I am trying to get the json data from an Angular service hero.service.ts. When using the fake http API inMemoryDataService, everything works fine and I am getting the json d

相关标签:
1条回答
  • 2020-12-06 14:23

    Found it ! It was due to the InMemoryBackendService and InMemoryDataService used in main.ts file, that seem to 'redirect' the calls from http.get method. Commenting those lines from main.ts file resolved the issue :

        // Imports for loading & configuring the in-memory web api
        import { XHRBackend } from '@angular/http';
    
        //import { InMemoryBackendService, SEED_DATA } from 'angular2-in-memory-web-api';
        //import { InMemoryDataService }               from './in-memory-data.service';
    
        // The usual bootstrapping imports
        import { bootstrap }      from '@angular/platform-browser-dynamic';
        import { HTTP_PROVIDERS } from '@angular/http';
    
        import { AppComponent }         from './app.component';
        import { appRouterProviders }   from './app.routes';
    
        bootstrap(AppComponent, [
            appRouterProviders,
            HTTP_PROVIDERS
            /*,
            { provide: XHRBackend, useClass: InMemoryBackendService }, // in-mem server
            { provide: SEED_DATA, useClass: InMemoryDataService }      // in-mem server data
            */
        ]);
    
    0 讨论(0)
提交回复
热议问题