0
votes

When I use http.get this is what I got. I try all solutions that I find here and none is working.

My code is from: http://docs.nativescript.org/angular/tutorial/ng-chapter-4

JS: EXCEPTION: Error in ./AppComponent class AppComponent_Host - inline template:0:0 caused by: Cannot read property 'getCookie' of null JS: ORIGINAL EXCEPTION: Cannot read property 'getCookie' of null JS: ORIGINAL STACKTRACE: JS: TypeError: Cannot read property 'getCookie' of null JS: at CookieXSRFStrategy.configureRequest (/data/data/org.nativescript.apka4/files/app/tns_modules/@angular/http/bundles/http.umd.js:1183:91) JS: at XHRBackend.createConnection (/data/data/org.nativescript.apka4/files/app/tns_modules/@angular/http/bundles/http.umd.js:1223:32) JS: at httpRequest (/data/data/org.nativescript.apka4/files/app/tns_modules/@angular/http/bundles/http.umd.js:1561:24) JS: at Http.request (/data/data/org.nativescript.apka4/files/app/tns_modules/@angular/http/bundles/http.umd.js:1661:38) JS: at Http.get (/data/data/org.nativescript.apka4/files/app/tns_modules/@angular/http/bundles/http.umd.js:1672:25) JS: at AppService.load (/data/data/org.nativescript.apka4/files/app/app.service.js:13:26) JS: at AppComponent.ngOnInit (/data/data/org.nativescript.apka4/files/app/app.component.js:11:25) JS: at Wrapper_AppComponent.detectChangesInInputProps (/AppComponentModule/AppComponent/wrapper.ngfactory.js:18:53) JS: at DebugAppView._View_AppComponent_Host0.detectChangesInternal (/AppComponentModule/AppComponent/host.ngfactory.js:36:26) JS: at DebugAppView.AppView.detectChanges (/data/data/org.nativescript.apka4/files/app/tns_modules/@angular/core/bundles/core.umd.js:9305:18)

2
Could you give more info about your case or to provide some code, where you made your HTTP request. In the mean time you could review the sample example here, where has been used NativeScript HttpModule - github.com/NativeScript/nativescript-sdk-examples-ng/tree/… - Nikolay Tsonev

2 Answers

1
votes

Can you please make sure you are importing the NativeScriptHttpModule in your main app module. You can see an example here.

It defines a provider for the Http which is the original Http service form @angular/http, but wrapped so that it can execute inside NativeScript.

0
votes

On your main.ts file you must import NativeScriptHttpModule see this:

import { NativeScriptHttpModule } from "nativescript-angular/http"; // import
@NgModule({
declarations: [
    AppComponent,
    ...appComponents,
],
bootstrap: [
    AppComponent
],
imports: [
    NativeScriptModule,
    NativeScriptHttpModule // add NativeScript Http module here
],
providers: [
    // your providers here
]})