Invalid 'this' to a Java object @ngx-translate NativeScript

plugins

#1

Hi everybody

I just trying to get work with @ngx-translate but when I try to run that on Android I just getting this error

System.err: Error: Trying to link invalid 'this' to a Java object
System.err: File: "file:///data/data/org.nativescript.projectname/files/app/tns_modules/tns-core-modules/ui/frame/fragment.transitions.js, line: 266, column: 35
System.err:

I did setup my app.module.ts file like this

import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core";
import { NativeScriptModule } from "nativescript-angular/nativescript.module";
import { AppRoutingModule } from "./app.routing";
import { AppComponent } from "./app.component";

import { ItemService } from "./item/item.service";
import { ItemsComponent } from "./item/items.component";
import { ItemDetailComponent } from "./item/item-detail.component";

import {NativeScriptHttpModule} from "nativescript-angular/http";
import {TranslateModule, TranslateLoader} from "@ngx-translate/core";
import {TranslateHttpLoader} from "@ngx-translate/http-loader";
import { HttpClientModule, HttpClient } from '@angular/common/http';


// for AoT compilation
export function translateLoaderFactory(http: HttpClient) {
    return new TranslateHttpLoader(http, "/i18n/", ".json");
};


@NgModule({
    bootstrap: [
        AppComponent
    ],
    imports: [
        NativeScriptModule,
        AppRoutingModule,
        NativeScriptHttpModule,
        TranslateModule.forRoot({
            loader: {
                provide: TranslateLoader,
                deps: [HttpClient],
                useFactory: (translateLoaderFactory)
            }
        })
    ],
    declarations: [
        AppComponent,
        ItemsComponent,
        ItemDetailComponent
    ],
    providers: [
        ItemService
    ],
    schemas: [
        NO_ERRORS_SCHEMA
    ]
})
/*
Pass your application module to the bootstrapModule function located in main.ts to start your app
*/
export class AppModule { }

and this is my package.json file

{
	"description": "NativeScript Application",
	"license": "SEE LICENSE IN <your-license-filename>",
	"readme": "NativeScript Application",
	"repository": "<fill-your-repository-here>",
	"nativescript": {
		"id": "org.nativescript.projectname",
		"tns-android": {
			"version": "3.2.0"
		},
		"tns-ios": {
			"version": "3.2.0"
		}
	},
	"dependencies": {
		"@angular/animations": "~4.4.1",
		"@angular/common": "~4.4.1",
		"@angular/compiler": "~4.4.1",
		"@angular/core": "~4.4.1",
		"@angular/forms": "~4.4.1",
		"@angular/http": "~4.4.1",
		"@angular/platform-browser": "~4.4.1",
		"@angular/router": "~4.4.1",
		"@ngx-translate/core": "^8.0.0",
		"@ngx-translate/http-loader": "^2.0.0",
		"nativescript-angular": "~4.4.0",
		"nativescript-theme-core": "~1.0.2",
		"reflect-metadata": "~0.1.8",
		"rxjs": "~5.4.2",
		"tns-core-modules": "~3.2.0",
		"zone.js": "~0.8.2"
	},
	"devDependencies": {
		"babel-traverse": "6.26.0",
		"babel-types": "6.26.0",
		"babylon": "6.18.0",
		"lazy": "1.0.11",
		"nativescript-dev-typescript": "~0.5.0",
		"typescript": "~2.4.2"
	}
}

please help me about that


#2

Hello,

in my project we use:

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

instead of:

import { HttpClientModule, HttpClient } from '@angular/common/http';

And use return new TranslateHttpLoader(http, “./i18n/”, “.json”);

I hope help you !
:slight_smile:


#3

I use Angular 5 and I have to use HTTP like this
import { HttpClientModule, HttpClient } from ‘@angular/common/http’;