I am busy with a small barcode scanner app which has a SettingsComponent where a local IP can be set. The app builds with no issues but when it gets deployed on a genymotion emulator I get the below error. It seems like it can't find SettingsComponent even though I imported it in my app.module.ts... (it gets added to the declarations array in the "...NavigatableComponents" code is below). Any idea why this is happening and How I can go about fixing it?
my error:
An uncaught Exception occurred on "main" thread. java.lang.RuntimeException: Unable to resume activity {org.nativescript.barcodescanner/com.tns.NativeScriptActivity}: com.tns.NativeScriptException: Calling js method onCreateView failed
Error: Component SettingsComponent is not part of any NgModule or the module has not been imported into your module. File: "/data/data/org.nativescript.barcodescanner/files/app/tns_modules/@angular/compiler/bundles/compiler.umd.js, line: 17126, column: 14
StackTrace:
Frame: function:'RuntimeCompiler._createCompiledHostTemplate', file:'/data/data/org.nativescript.barcodescanner/files/app/tns_modules/@angular/compiler/bundles/compiler.umd.js', line: 17126, column: 21 Frame: function:'', file:'/data/data/org.nativescript.barcodescanner/files/app/tns_modules/@angular/compiler/bundles/compiler.umd.js', line: 17085, column: 39 Frame: function:'', file:'/data/data/org.nativescript.barcodescanner/files/app/tns_modules/@angular/compiler/bundles/compiler.umd.js', line: 17083, col
my settings.html:
<StackLayout class="page">
<Label class="h1 title m-x-auto " text="Settings"></Label>
<StackLayout class="form" *ngIf="!IPSaved">
<TextField class="form-input border" placeholder="Enter IP"></TextField>
<Button class="btn btn-primary" text="Submit"></Button>
</StackLayout>
<StackLayout *ngIf="IPSaved">
<Label class="h1" text="IP Submitted successfully"></Label>
<Button class="btn btn-primary" text="Done" [nsRouterLink]="['/home']"></Button>
</StackLayout>
</StackLayout>
my settings.component.ts:
import { Component,} from '@angular/core';
import { RestService } from '../../services/rest.service';
import { AppSettingsService } from '../../services/app-settings.service';
@Component({
selector: 'settings',
templateUrl: './pages/settings/settings.component.html'
})
export class SettingsComponent {
ipSaved: boolean;
constructor(private restService: RestService, private appSettingsService: AppSettingsService) {
}
submitIP(ip: string) {
this.appSettingsService.saveLocalIP(ip);
this.restService.init(ip);
this.ipSaved = true;
}
}
my app.module.ts:
import { NgModule, ValueProvider } from "@angular/core";
import { NativeScriptFormsModule } from "nativescript-angular/forms";
import { NativeScriptModule } from "nativescript-angular/platform";
import { NativeScriptRouterModule } from 'nativescript-angular/router'
import { NativeScriptHttpModule } from 'nativescript-angular/http';
import { BarcodeScanner } from "nativescript-barcodescanner";
import { RestService } from './services/rest.service';
import { appSettingsService } from './services/app-settings.service';
import { AppComponent } from "./app.component";
import { HomeComponent } from "./pages/home/home.component";
import { CheckBarcodesComponent } from './pages/check-barcodes/check-barcodes.component';
import { SettingsComponent } from './pages/settings/settings.component';
import { routes, navigatableComponents } from './app.routing';
@NgModule({
imports : [
NativeScriptModule,
NativeScriptFormsModule ,
NativeScriptHttpModule,
NativeScriptRouterModule,
NativeScriptRouterModule.forRoot(routes)
],
declarations : [
AppComponent,
...navigatableComponents
],
providers : [
RestService,
BarcodeScanner],
bootstrap : [AppComponent]
})
export class AppModule {}
my app.routing.ts:
import { AppComponent } from './app.component';
import { HomeComponent } from './pages/home/home.component';
import { CheckBarcodesComponent } from './pages/check-barcodes/check-barcodes.component';
import { SettingsComponent } from './pages/settings/settings.component';
export const routes = [
{path: "", component: HomeComponent},
{path: "checkBarcodes", component: CheckBarcodesComponent},
{path: "settings", component: SettingsComponent}
];
export const navigatableComponents = [
HomeComponent,
CheckBarcodesComponent,
SettingsComponent
];
Guessing a bit, but I think app.module.ts
should have this import: import { AppSettingsService } from './services/app-settings.service';
(mind uppercase 'A') and you need to add AppSettingsService
to the list of providers
in the same class.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.