简体   繁体   English

找不到模块:错误:无法解析“/Users/username/Documents/Privat/ionic3-barcodev3/src/app/home”中的“./home.html”

[英]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.我刚刚开始在 android 上使用条形码扫描仪构建我的第一个 ionic 应用程序。 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:主页.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:主页.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: 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?检查这个问题: 我必须在哪里导入 Ionic 3 上的页面?

You need to import homepage in app.module.ts您需要在 app.module.ts 中导入主页

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

and in declarations and entryComponents in the same file app.modules.ts.并在同一个文件 app.modules.ts 中的声明entryComponents中。

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. entryComponents :在 entryComponents 部分,我们定义任何仅按其类型加载的组件。 This is the case for all Page components.所有 Page 组件都是这种情况。

暂无
暂无

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

相关问题 找不到模块:错误:无法解析“/home/user/Desktop/my_app/src”中的“./app” - Module not found: Error: Can't resolve './app' in '/home/user/Desktop/my_app/src' 找不到模块:错误:无法解析“主页” - Module not found: Error: Can't resolve 'Home' 找不到模块:错误:无法在“/home/yusquen/Projectss/react-shop/src/components”中解析“../containers/Layout” - Module not found: Error: Can't resolve '../containers/Layout' in '/home/yusquen/Projectss/react-shop/src/components' 找不到模块:无法解析“/home/n/MyWork/my-app/src”中的“./clock” - Module not found: Can't resolve './clock' in '/home/n/MyWork/my-app/src' 离子,home.html无法识别<script> - Ionic, home.html do not recognize <script> 错误:ENOENT:没有这样的文件或目录,stat '/var/task/src/functions/public/home.html' - Error: ENOENT: no such file or directory, stat '/var/task/src/functions/public/home.html' 多个./main.js中的错误。 找不到模块:错误:无法解析&#39;/ home / user / workspace / webpack&#39; - ERROR in multi ./main.js . Module not found: Error: Can't resolve '/home/user/workspace/webpack' 找不到模块:无法解析“/home/sanika/Desktop/Coding/React/my-forms/src/Components”中的“@material-ui/lab/TabContext” - Module not found: Can't resolve '@material-ui/lab/TabContext' in '/home/sanika/Desktop/Coding/React/my-forms/src/Components' 找不到模块:错误:无法解析&#39;/ Users / jonathankuhl / Documents / Programming / node js / sandbox / webpack-app&#39;中的&#39;bundle.js&#39; - Module not found: Error: Can't resolve 'bundle.js' in '/Users/jonathankuhl/Documents/Programming/node js/sandbox/webpack-app' 未找到 ./src/App.jsx 模块中的错误:错误:无法解析“./component/Footer” - ERROR in ./src/App.jsx Module not found: Error: Can't resolve './component/Footer'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM