Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using angular2 services outside of an angular app

I have an angular2 app with services making Http calls to the server api. How can I call just these services in a different app that uses react.js without bootstrapping the angular2 or without using angular components.

App1(angular2) -> component1 -> SharedService1(say http api client)
                                 ^ 
                                 |(call service from react to get data)
App2(react)             ->     React Component     
like image 457
Rjk Avatar asked Nov 26 '25 08:11

Rjk


1 Answers

Just create a new injector with HTTP_PROVIDERS and acquire Http from it like:

let injector = ReflectiveInjector.resolveAndCreate([HTTP_PROVIDERS]);
let http = injector.get(Http);
http.get('http://someurl').subscribe(...)
like image 127
Günter Zöchbauer Avatar answered Nov 28 '25 20:11

Günter Zöchbauer