Angular 如何修复使用modals时的ionic 4错误

Angular 如何修复使用modals时的ionic 4错误,angular,ionic-framework,modal-dialog,ionic4,Angular,Ionic Framework,Modal Dialog,Ionic4,我试图使用两个模态来显示使用条款和免责声明。它在离子实验室工作 当我尝试为android构建时,出现以下错误: ERROR in : Type DisclaimerPage in C:/ionic/EMSPROv1/src/app/pages/disclaimer/disclaimer.page.ts is part of the declarati ons of 2 modules: HomePageModule in C:/ionic/EMSPROv1/src/app/home/home.m

我试图使用两个模态来显示使用条款和免责声明。它在离子实验室工作

当我尝试为android构建时,出现以下错误:

ERROR in : Type DisclaimerPage in C:/ionic/EMSPROv1/src/app/pages/disclaimer/disclaimer.page.ts is part of the declarati
ons of 2 modules: HomePageModule in C:/ionic/EMSPROv1/src/app/home/home.module.ts and DisclaimerPageModule in C:/ionic/E
MSPROv1/src/app/pages/disclaimer/disclaimer.module.ts! Please consider moving DisclaimerPage in C:/ionic/EMSPROv1/src/ap
p/pages/disclaimer/disclaimer.page.ts to a higher module that imports HomePageModule in C:/ionic/EMSPROv1/src/app/home/h
ome.module.ts and DisclaimerPageModule in C:/ionic/EMSPROv1/src/app/pages/disclaimer/disclaimer.module.ts. You can also
create a new NgModule that exports and includes DisclaimerPage in C:/ionic/EMSPROv1/src/app/pages/disclaimer/disclaimer.
page.ts then import that NgModule in HomePageModule in C:/ionic/EMSPROv1/src/app/home/home.module.ts and DisclaimerPageM
odule in C:/ionic/EMSPROv1/src/app/pages/disclaimer/disclaimer.module.ts.
我也尝试过在app.module.ts中添加导入,但仍然出现相同的错误

import { GetMenuService } from './../services/get-menu.service';
import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Routes, Router } from '@angular/router';
import { map } from 'rxjs/operators';
import { Observable } from 'rxjs';
import {ModalController, NavController} from '@ionic/angular';
import { GoogleAnalytics } from '@ionic-native/google-analytics/ngx';
import { Storage } from '@ionic/storage';
import { AlertController } from '@ionic/angular';
import { DisclaimerPage } from '../pages/disclaimer/disclaimer.page';
import { TermsConditionsPage } from '../pages/terms-conditions/terms-conditions.page';

@Component({
  selector: 'app-home',
  templateUrl: 'home.page.html',
  styleUrls: ['home.page.scss'],
})
export class HomePage implements OnInit {
    results: Observable<any>;
    analyticsPage = 'Home';
    disclaimerAgreed = 'No';
    termsAgreed = 'No';

    dataReturned: any;

    quickCallNumber = '';


  constructor(private menuService: GetMenuService, private router: Router, private ga: GoogleAnalytics,
              public storage: Storage, public alertController: AlertController, public modalController: ModalController) { }

    async presentTerms() {
        const modal = await this.modalController.create({
            component: TermsConditionsPage
        });

        await modal.present();
    }

  async presentDisclaimer() {
      const modal = await this.modalController.create({
        component: DisclaimerPage
      });

      await modal.present();
  }

  ngOnInit() {
        this.analyticsStart(this.analyticsPage);
        console.log('ngOnInit');
        this.results = this.menuService.getMenu2('menu1');
        console.log(this.results);

        this.storage.get('quickCallNumber').then((val) => {
              console.log('quickCallNumber', val);
              if (val === null || val === '') {
                this.storage.set('quickCallNumber', '610-973-1625');
                this.quickCallNumber = '610-973-1625';
              } else {
                this.quickCallNumber = val;
              }
        });

        this.storage.get('termsAgreed').then((val) => {
          console.log('termsAgreed', val);
          if (val === null || val === '') {
              this.termsAgreed = 'No';
          } else {
              this.termsAgreed = val;
          }
          if (this.termsAgreed === 'No') {
              this.presentTerms();
          }
        });

        this.storage.get('disclaimerAgreed').then((val) => {
            console.log('disclaimerAgreed', val);
            if (val === null || val === '') {
                  this.disclaimerAgreed = 'No';
            } else {
                  this.disclaimerAgreed = val;
            }
            if (this.disclaimerAgreed === 'No') {
              this.presentDisclaimer();
            }
        });
  }

    // Go to a specific url
    goToLink(url: string) {
      console.log('goToLink', url);
      window.open(url, '_blank');
    }
    // Dial phone number by using TEL
    dialNumber(phone: string) {
        console.log('goToPhone', phone);
        this.analyticsTrack('Dial Number', phone);
        window.open('tel://' + phone, '_blank');
    }

    // ---------------------------------------------------------------
    // ---------------------------------------------------------------
    // GOOGLE ANALYTICS
    // ---------------------------------------------------------------
    // ---------------------------------------------------------------
    analyticsStart(value) {
        this.ga.startTrackerWithId('UA-142662811-2')
            .then(() => {
                console.log('Google analytics is ready now');
                this.ga.trackView(value + ' Screen');
                // Tracker is ready
                // You can now track pages or set additional information such as AppVersion or UserId
                this.analyticsTrack('Page', 'View');
            })
            .catch(e => console.log('Error starting GoogleAnalytics', e));
    }
    analyticsTrack(event, label) {
        this.ga.trackEvent(this.analyticsPage, event, label, 1);
    }

}
从“/../services/get menu.service”导入{GetMenuService};
从“@angular/core”导入{Component,OnInit};
从'@angular/Router'导入{ActivatedRoute,Routes,Router};
从“rxjs/operators”导入{map};
从“rxjs”导入{Observable};
从'@ionic/angular'导入{ModalController,NavController};
从'@ionic native/google analytics/ngx'导入{GoogleAnalytics};
从'@ionic/Storage'导入{Storage};
从'@ionic/angular'导入{AlertController};
从“../pages/disclaimer/disclaimer.page”导入{DisclaimerPage};
从“../pages/terms-conditions/terms-conditions.page”导入{TermsConditionsPage};
@组成部分({
选择器:“应用程序主页”,
templateUrl:'home.page.html',
样式URL:['home.page.scss'],
})
导出类主页实现OnInit{
结果:可观察;
分析空间=‘家’;
免责声明='否';
termsAgreed=‘否’;
返回的数据:任何;
quickCallNumber='';
构造函数(专用menuService:GetMenuService,专用路由器:路由器,专用ga:GoogleAnalytics,
公共存储:存储,公共alertController:alertController,公共modalController:modalController{}
异步presentTerms(){
const modal=等待this.modalController.create({
组件:TermsConditionsPage
});
等待模态present();
}
异步呈现免责声明(){
const modal=等待this.modalController.create({
组成部分:免责声明页
});
等待模态present();
}
恩戈尼尼特(){
this.analyticsStart(this.analyticsPage);
console.log('ngOnInit');
this.results=this.menuService.getMenu2('menu1');
console.log(this.results);
this.storage.get('quickCallNumber')。然后((val)=>{
console.log('quickCallNumber',val);
如果(val==null | | val===''){
此.storage.set('quickCallNumber','610-973-1625');
this.quickCallNumber='610-973-1625';
}否则{
this.quickCallNumber=val;
}
});
this.storage.get('termsAgreed')。然后((val)=>{
console.log('termsAgreed',val);
如果(val==null | | val===''){
this.termsAgreed='No';
}否则{
this.termsAgreed=val;
}
如果(this.termsAgreed==='No'){
这个。presentTerms();
}
});
this.storage.get('disclaimerAgreed')。然后((val)=>{
console.log('免责声明',val);
如果(val==null | | val===''){
this.disclaimerAgreed='No';
}否则{
this.disclaimerAgreed=val;
}
如果(this.disclaimerAgreed=='No'){
此.present免责声明();
}
});
}
//转到特定的url
goToLink(url:string){
log('goToLink',url);
打开(url,“U空白”);
}
//用电话拨电话号码
拨号号码(电话:字符串){
console.log('goToPhone',phone);
此。分析列表(“拨号号码”,电话);
窗口打开('tel://'+phone,'u blank');
}
// ---------------------------------------------------------------
// ---------------------------------------------------------------
//谷歌分析
// ---------------------------------------------------------------
// ---------------------------------------------------------------
分析启动(值){
本文件为ga.startTrackerWithId('UA-142662811-2')
.然后(()=>{
log(“谷歌分析已经准备好了”);
this.ga.trackView(值+屏幕);
//跟踪器准备好了
//您现在可以跟踪页面或设置附加信息,如AppVersion或UserId
这个.analyticsTrack('Page','View');
})
.catch(e=>console.log('Error start GoogleAnalytics',e');
}
分析列表(事件、标签){
this.ga.trackEvent(this.analyticsPage,event,label,1);
}
}

正如我所说,它在ionic lab emulator中工作,但在我尝试编译时不起作用。

您需要创建某种共享模块

import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';


//Import components here and the import this ImporterModule where it is used --> example it is imported in auction-result-module.ts
import { DisclaimerPage } from "YOUR_PATH";



//We used the ImporterModule because angular gives an error if one component is imported in several places
@NgModule({
    imports: [
        CommonModule, FormsModule, ReactiveFormsModule
    ],
    entryComponents: [
        DisclaimerPage
    ],
    declarations: [
        DisclaimerPage
    ],
    exports: [
        DisclaimerPage
    ],
    schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
export class ImporterModule { }
然后在需要使用免责声明页的地方导入共享模块

Angular不允许在多个位置导入零部件

因此出现了错误

在C:/ionic/EMSPROv1/src/app/pages/disclaimer/disclaimer.page.ts中键入DisclaimerPage是声明的一部分 两个模块的构造