我刚刚开始使用android上的条形码扫描仪构建我的第一个离子应用程序。为了开发条形码集成,我使用了以下文档:link
一段时间以来,它似乎完全正常。但是现在我收到了此错误消息:
Module not found: Error: Can't resolve './home.html' in '/Users/username/Documents/Privat/ionic3-barcodev3/src/app/home'
有人知道如何解决该问题吗?
home.page.html:
<ion-header>
<ion-toolbar color="primary">
<ion-title>
QR-Scanner
</ion-title>
</ion-toolbar>
</ion-header>
<ion-content padding>
<ion-button color="success" expand="full" shape="round" (click)="scan()">Start Scan</ion-button>
<ion-card *ngIf="productFound">
<ion-card-header>
<h2 color="success" >Object: {{selectedProduct.name}}</h2>
</ion-card-header>
<ion-card-content>
<ul>
<li>{{selectedProduct.plu}}</li>
<li>{{selectedProduct.price}}</li>
<li>{{selectedProduct.desc}}</li>
</ul>
</ion-card-content>
</ion-card>
</ion-content>
home.page.ts:
import { NavController } from '@ionic/angular';
import { Component } from '@angular/core';
import { BarcodeScanner } from '@ionic-native/barcode-scanner/ngx';
import { Toast } from '@ionic-native/toast/ngx';
import { DataServiceService } from '../../app/data-service.service';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
products: any[] = [];
selectedProduct: any;
productFound:boolean = false;
constructor(public navCtrl: NavController,
private barcodeScanner: BarcodeScanner,
private toast: Toast,
public dataService: DataServiceService) {
this.dataService.getProducts()
.subscribe((response)=> {
this.products.push(response)
console.log(this.products);
});
}
scan() {
this.selectedProduct = {};
this.barcodeScanner.scan().then((barcodeData) => {
this.selectedProduct = this.products.find(product => product.plu === barcodeData.text);
if(this.selectedProduct !== undefined) {
this.productFound = true;
console.log(this.selectedProduct);
} else {
this.selectedProduct = {};
this.productFound = false;
this.toast.show('Product not found', '5000', 'center').subscribe(
toast => {
console.log(toast);
}
);
}
}, (err) => {
this.toast.show(err, '5000', 'center').subscribe(
toast => {
console.log(toast);
}
);
});
}
}
app.module.ts:
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';
import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
import { SplashScreen } from '@ionic-native/splash-screen/ngx';
import { StatusBar } from '@ionic-native/status-bar/ngx';
import { AppComponent } from './app.component';
import { AppRoutingModule } from './app-routing.module';
import { BarcodeScanner } from '@ionic-native/barcode-scanner/ngx';
import { Toast } from '@ionic-native/toast/ngx';
import { HttpClientModule } from '@angular/common/http';
@NgModule({
declarations: [AppComponent],
entryComponents: [],
imports: [BrowserModule,
IonicModule.forRoot(),
AppRoutingModule,
HttpClientModule
],
providers: [
StatusBar,
SplashScreen,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
BarcodeScanner,
Toast
],
bootstrap: [AppComponent]
})
export class AppModule {}
答案 0 :(得分:1)
检查以下问题:Where do I have to import a page on Ionic 3?
您需要在app.module.ts中导入主页
import { HomePage } from '../pages/home/home';
以及同一文件app.modules.ts中的声明和 entryComponents 。
declarations: [
... ,
HomePage
],
entryComponents: [
... ,
HomePage
],
声明:在声明部分,我们需要包括我们创建的所有组件和指令。
entryComponents :在entryComponents部分中,我们定义了仅按类型加载的任何组件。所有Page组件都是这种情况。