No provider for Http error when sharing code between Web and Mobile using a symlinked directory


#1

I’m trying to create a project with Angular 4 and NativeScript with a single codebase as mentioned in this article (http://shripalsoni.com/blog/create-native-mobile-and-web-app-with-single-codebase-using-angular2-and-nativescript/). What it basically does is maintaining a directory that contains shared components such as services and symlinking it to the web and NativeScript directories. However, when I’m trying to make a HTTP call from a service that is located in the symlinked directory, I’m getting the error

Uncaught (in promise): Error: No provider for Http!

in the browser console. I have already imported the HttpModule into the app.module.ts.


#2

@sebawita any ideas here?


#3

Hi @great_white,
Is this error inside a web or mobile app?
For NativeScript you need to import NativeScriptHttpModule

Also I have a feeling that you might have the same issue, as the one I had when I moved my services into an npm module. In this case you may need to inject the service using forwardRef, like this:

constructor(@Inject(forwardRef(() => Http)) private http: Http) {
}

Here is a service I’ve created using forward ref:

Thanks,
Sebastian


#4

Hi Sebawita,

Thank you for the response. I got this issue resolved. Sorry for the late reply.