"Trying to link invalid 'this' to a Java object, undefined"

plugins

#1

Hello

I’m trying to use the HttpClient module from the @angular/common/http plugin.

I create a brand new app using the command: tns create HelloWorld --template nativescript-template-ng-tutorial.

I then add the two lines to the app.module.ts, one as an import and the other in the imports:[] section, for the HttpClientModule module.

However, when the app runs on my android phone, it displays the message “Trying to link invalid ‘this’ to a Java object, undefined”. If I remove the HttpClientModule from the imports:[] section, the app starts correctly on my phone.

Am I using the @angular/common/http module correctly? My package.json file is listed below.

Thanks
John

import { NgModule, NO_ERRORS_SCHEMA } from “@angular/core”;
import { NativeScriptModule } from “nativescript-angular/nativescript.module”;
import { HttpClientModule } from ‘@angular/common/http’;
import { AppComponent } from “./app.component”;

@NgModule({
declarations: [AppComponent],
bootstrap: [AppComponent],
imports: [
NativeScriptModule,
HttpClientModule
],
schemas: [NO_ERRORS_SCHEMA],
})
export class AppModule {}

Package.json:
{
“description”: “NativeScript Application”,
“license”: “SEE LICENSE IN “,
“readme”: “NativeScript Application”,
“repository”: “”,
“nativescript”: {
“id”: “org.nativescript.HelloWorld4”,
“tns-android”: {
“version”: “3.3.0”
}
},
“dependencies”: {
@angular/animations”: “~4.4.5”,
"@angular/common": “~4.4.5”,
"@angular/compiler": “~4.4.5”,
"@angular/core": “~4.4.5”,
"@angular/forms": “~4.4.5”,
"@angular/http": “~4.4.5”,
"@angular/platform-browser": “~4.4.5”,
"@angular/router": “~4.4.5”,
“nativescript-angular”: “~4.4.1”,
“nativescript-theme-core”: “~1.0.4”,
“reflect-metadata”: “~0.1.8”,
“rxjs”: “~5.4.2”,
“tns-core-modules”: “~3.1.1”,
“zone.js”: “~0.8.2”
},
“devDependencies”: {
“babel-traverse”: “6.4.5”,
“babel-types”: “6.4.5”,
“babylon”: “6.4.5”,
“lazy”: “1.0.11”,
“nativescript-dev-typescript”: “~0.5.0”,
“typescript”: “~2.4.2”
}
}


#2

I’m also getting this error. Have you managed to get HttpClientModule to work?


#3

It seems that we should use NativeScriptHttpClientModule from nativescript-angular/http-client instead. Source


#4

Hi Chernov - thankyou for your reply. That worked perfectly.