简体   繁体   中英

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     

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(...)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM