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

时间:2017-01-05 21:35:32

标签: angular nativescript

我正忙着一个小型条码扫描器应用程序,它有一个SettingsComponent,可以设置本地IP。该应用程序构建没有问题,但当它在genymotion模拟器上部署时,我得到以下错误。它似乎无法找到SettingsComponent,即使我在app.module.ts中导入它...(它被添加到“... NavigatableComponents”代码中的声明数组中)。知道为什么会发生这种情况以及如何解决这个问题?

我的错误:

  

“主”线程上发生了未被捕获的异常。   java.lang.RuntimeException:无法恢复活动{org.nativescript.barcodescanner / com.tns.NativeScriptActivity}:com.tns.NativeScriptException:   调用js方法onCreateView失败

     

错误:组件SettingsComponent不是任何NgModule的一部分,或者模块尚未导入模块。   文件:“/ data / data / arch.nativescript.barcodescanner / files / app / tns_modules / @ angular/compiler/bundles/compiler.umd.js,line:17126,column:14

StackTrace:

  

框架:功能:'RuntimeCompiler._createCompiledHostTemplate',file:'/ data/data/org.nativescript.barcodescanner/files/app/tns_modules/@angular/compiler/bundles/compiler.umd.js',line:17126 ,专栏:21   框架:功能:'',file:'/ data/data/org.nativescript.barcodescanner/files/app/tns_modules/@angular/compiler/bundles/compiler.umd.js',line:17085,column:39   框架:功能:'',文件:'/ data/data/org.nativescript.barcodescanner/files/app/tns_modules/@angular/compiler/bundles/compiler.umd.js',行: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>

我的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;
    }

}

我的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 {}

我的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
];

1 个答案:

答案 0 :(得分:1)

稍微猜一下,但我认为app.module.ts应该进行此导入:import { AppSettingsService } from './services/app-settings.service';(请注意大写&#39; A&#39;)并且您需要将AppSettingsService添加到列表中providers在同一个班级。

相关问题