简体   繁体   中英

Module not found: Error: Can't resolve './home.html' in '/Users/username/Documents/Privat/ionic3-barcodev3/src/app/home'

I just started to build my first ionic app with a barcode scanner on android. For the development of the barcode integration I used this documentation: link

For a while it seemed to work totally fine. But now I got this error message:

 Module not found: Error: Can't resolve './home.html' in '/Users/username/Documents/Privat/ionic3-barcodev3/src/app/home'

Anyone an idea how to solve that issue?

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

Check this question: Where do I have to import a page on Ionic 3?

You need to import homepage in app.module.ts

import { HomePage } from '../pages/home/home';

and in declarations and entryComponents in the same file app.modules.ts.

declarations: [
    ... ,
    HomePage
],
entryComponents: [
    ... ,
    HomePage
],

declarations : In the declarations section we need to include all components and directives we create.

entryComponents : In the entryComponents section we define any component that is only loaded by its type. This is the case for all Page components.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM