Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NativeScript No provider for Http

Am following the NativeScript Groceries Typescript Angular tutorial and I got stuck in chapter 3 with the following errors.

EXCEPTION: Error in ./AppComponent class AppComponent_Host - inline template:0:0
ORIGINAL EXCEPTION: No provider for Http!
ORIGINAL STACKTRACE:
Error: DI Exception
at NoProviderError.BaseException [as constructor] (/data/data/org.nativescript.groceries/files/app/tns_modules/@angular/core/src/facade/exceptions.js:27:23)
at NoProviderError.AbstractProviderError [as constructor] (/data/data/org.nativescript.groceries/files/app/tns_modules/@angular/core/src/di/reflective_exceptions.js:43:16)
at new NoProviderError (/data/data/org.nativescript.groceries/files/app/tns_modules/@angular/core/src/di/reflective_exceptions.js:80:16)
at ReflectiveInjector_._throwOrNull (/data/data/org.nativescript.groceries/files/app/tns_modules/@angular/core/src/di/reflective_injector.js:786:19)
at ReflectiveInjector_._getByKeyDefault (/data/data/org.nativescript.groceries/files/app/tns_modules/@angular/core/src/di/reflective_injector.js:814:25)
at ReflectiveInjector_._getByKey (/data/data/org.nativescript.groce

I have gone back and forth the tutorial to see if I missed something but it seems I followed every steps diligently.

How do I resolve this issue.

like image 325
ammezie Avatar asked Aug 29 '16 10:08

ammezie


2 Answers

Update

If you got here because of the NativeScript Angular2 Typescript tutorial, the next step fixes the problem (at the time of this writing).

Original

Apparently, a step is missing from the tutorial.

I had to add the following 2 lines:

// app.module.ts

import { NativeScriptHttpModule } from "nativescript-angular";

NativeScriptHttpModule

I ended with the following (app.module.ts):

import { NgModule } from "@angular/core";
import { NativeScriptFormsModule } from "nativescript-angular/forms";
import { NativeScriptModule } from "nativescript-angular/platform";
import { NativeScriptHttpModule } from "nativescript-angular";

import { AppComponent } from "./app.component";

@NgModule({
  imports: [
    NativeScriptModule,
    NativeScriptFormsModule,
    NativeScriptHttpModule
  ],
  declarations: [AppComponent],
  bootstrap: [AppComponent]
})
export class AppModule { }
like image 73
Rick Love Avatar answered Oct 13 '22 03:10

Rick Love


Good Morning usually this error is caused by not bootstrapping the HTTP_PROVIDER in your application like so:

 import { HTTP_PROVIDERS } from '@angular/http';

 nativeScriptBootstrap(AppComponent, [HTTP_PROVIDERS]);
like image 30
JoshSommer Avatar answered Oct 13 '22 03:10

JoshSommer