0

I have a tons of problems with one project where a lot of code was wrote ar rc4 and now I should migrate it to release version. I don't know how, because in off. google docs migrations process from rc4 to rc5 removed. So I tried to do that manually.

now I have issue with creating http module outside of app.

here is previous code. It used for receiving routes config from server before app starting.

/**
 *  FakeXSRFStrategy and XRSF_MOCK fix http routes loading before bootstrap()
 *  https://github.com/angular/angular/issues/9294
 */
 class FakeXSRFStrategy implements XSRFStrategy {
   public configureRequest(req: Request) {}
 }
 const XRSF_MOCK = provide(XSRFStrategy, { useValue: new FakeXSRFStrategy() });

 const injector = ReflectiveInjector.resolveAndCreate([HTTP_PROVIDERS, XRSF_MOCK]);
 const http = injector.get(Http);

After upgrade it not works. I was looking at forums etc. and I found that HttpModule should be used instead HTTP_PROVIDERS in rc5

I tried to do that stuff

import {AsyncRoute} from '@angular/router-deprecated';
import {ReflectiveInjector, provide} from '@angular/core';
import {HttpModule, Http, Request, XSRFStrategy} from '@angular/http';
import 'rxjs/Rx';

const injector = ReflectiveInjector.resolveAndCreate([HttpModule]);
const http = injector.get(Http);

But it's not works. I got message - (SystemJS) No provider for Http! I don't know what to do. Please, help me. Thanks.

Velidan
  • 5,526
  • 10
  • 48
  • 86
  • Thanks guys, but I don't have a ng2 component. It's simply class (outside of angular2) where I want to get http. I don't know how I can use ngModule inside it. – Velidan Oct 03 '16 at 11:04
  • Just use it as `HTTP_PROVIDERS` https://plnkr.co/edit/OEtkkWAGdmC7DrYk0r4p?p=preview – yurzui Oct 03 '16 at 11:11
  • Thanks for help. I created http module but it still not works **(SystemJS) Cannot read property 'getCookie' of null** . when I tried to use it like http.get(this._routesDatatUrl).map(res => res.json()).subscribe(data => console.log(data)); – Velidan Oct 03 '16 at 12:10
  • Unfortunatelly I can't fix it so I used native ajax instead ng2 http. Now it works. – Velidan Oct 04 '16 at 15:18

0 Answers0