简体   繁体   English

Angular2/nativeScript:奇怪的错误,抱怨组件未导入任何模块,即使它已导入主模块

[英]Angular2/nativeScript: Strange error complaining about a component that's not imported into any module even though it is imported in the main module

I am busy with a small barcode scanner app which has a SettingsComponent where a local IP can be set.我正忙于一个小型条码扫描仪应用程序,它有一个可以设置本地 IP 的 SettingsComponent。 The app builds with no issues but when it gets deployed on a genymotion emulator I get the below error.该应用程序构建没有问题,但是当它部署在 genymotion 模拟器上时,我收到以下错误。 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).即使我将它导入到我的 app.module.ts 中,它似乎也找不到 SettingsComponent...(它被添加到下面的“...NavigatableComponents”代码中的声明数组中)。 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 java.lang.RuntimeException:无法恢复活动 {org.nativescript.barcodescanner/com.tns.NativeScriptActivity}:com.tns.NativeScriptException:调用 js 方法 onCreateView 失败

Error: Component SettingsComponent is not part of any NgModule or the module has not been imported into your module.错误:组件设置组件不是任何 NgModule 的一部分,或者该模块尚未导入到您的模块中。 File: "/data/data/org.nativescript.barcodescanner/files/app/tns_modules/@angular/compiler/bundles/compiler.umd.js, line: 17126, column: 14文件:“/data/data/org.nativescript.barcodescanner/files/app/tns_modules/@angular/compiler/bundles/compiler.umd.js,行:17126,列: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框架:函数:'RuntimeCompiler._createCompiledHostTemplate',文件:'/data/data/org.nativescript.barcodescanner/files/app/tns_modules/@angular/compiler/bundles/compiler.umd.js',行:17126,列: 21 Frame: function:'', file:'/data/data/org.nativescript.barcodescanner/files/app/tns_modules/@angular/compiler/bundles/compiler.umd.js', line: 17085, column: 39 Frame :函数:'',文件:'/data/data/org.nativescript.barcodescanner/files/app/tns_modules/@angular/compiler/bundles/compiler.umd.js',行:17083,col

my settings.html:我的设置.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:我的 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:我的 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:我的 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';有点猜测,但我认为app.module.ts应该有这个导入: 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. (注意大写'A')并且您需要将AppSettingsService添加到同一类中的providers列表中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Angular2:行为很奇怪,即使组件未导入到app.module中,也会出现错误提示该组件未导入 - Angular2: Very strange behaviour, error complaining about a component that's not imported even though it is imported in app.module Angular2 无法识别来自导入模块的组件 - Angular2 Not Recognizing component From Imported Module angular2使用嵌套导入模块的组件 - angular2 use component of nested imported module 单元测试带有导入模块的angular2组件 - Unit Testing angular2 component with imported module Angular2-导入组件时找不到模块 - Angular2 - module not being found when imported into component 角; 错误:组件 NewPharmacyComponent 不是任何 NgModule 的一部分,或者该模块尚未导入到您的模块中 - Angular; Error: Component NewPharmacyComponent is not part of any NgModule or the module has not been imported into your module Angular:未捕获错误:组件 BucketGridComponent 不是任何 NgModule 的一部分,或者该模块尚未导入您的模块 - Angular: Uncaught Error: Component BucketGridComponent is not part of any NgModule or the module has not been imported into your module Angular 7-从导入的模块获取组件 - Angular 7 - Getting Component from imported Module Angular/NX - 组件不是已知元素,但它是在模块中导入的 - Angular/NX - Component is not a known element, but it is imported in the module 导入 Angular 功能模块时渲染组件 - Render a Component when a Angular Feature module is imported
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM