Как исправить ионные 4 ошибки при использовании модальных - PullRequest
1 голос
/ 08 июля 2019

Я пытаюсь использовать два модальных режима для отображения условий использования и отказа от ответственности.Это работает в ионной лаборатории.

Когда я пытаюсь собрать для 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);
    }

}

Как я уже сказал, он работает в эмуляторе ионной лаборатории, но не когда я пытаюсь скомпилировать.

1 Ответ

1 голос
/ 08 июля 2019

Вам нужно создать какой-то общий модуль

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

Затем импортируйте общий модуль туда, где вам когда-либо потребуется использовать disclaimerPage

Angular не позволит вам импортировать компонент в несколькомест

Следовательно, ошибка

Тип DisclaimerPage в C: /ionic/EMSPROv1/src/app/pages/disclaimer/disclaimer.page.ts является частью объявлений 2 модулей

...