AlertController错误:无法读取未定义的属性“ _getPortal”

时间:2018-07-22 00:59:51

标签: ionic-framework ionic3

不久前,我在ionic forum问了这个问题,但没有得到答案!在StackOverflow中已经提出了类似的问题,但是没有一个问题可以解决。我尝试按照建议的here.forRoot(...)中删除components.module.ts。我还尝试按照建议的here将组件扩展为viewcontroller。而且我的代码与单元测试无关,因此其他解决方案不适用。

我正在使用Ionic v3.20.0。 AlertController给我以下错误:

Runtime Error Cannot read property '_getPortal' of undefined Stack TypeError: Cannot read property '_getPortal' of undefined at App.present (http://localhost:8100/build/vendor.js:22543:36) at Alert.present (http://localhost:8100/build/vendor.js:58761:26) at TermsAndConditionsPage.webpackJsonp.360.TermsAndConditionsPage.showBasicAlert (http://localhost:8100/build/1.js:333:20) at Object.eval [as handleEvent] (ng:///TermsAndConditionsPageModule/TermsAndConditionsPage.ngfactory.js:43:31) at handleEvent (http://localhost:8100/build/vendor.js:13963:155) at callWithDebugContext (http://localhost:8100/build/vendor.js:15472:42) at Object.debugHandleEvent [as handleEvent] (http://localhost:8100/build/vendor.js:15059:12) at dispatchEvent (http://localhost:8100/build/vendor.js:10378:25) at http://localhost:8100/build/vendor.js:11003:38 at HTMLButtonElement.<anonymous> (http://localhost:8100/build/vendor.js:39492:53) Ionic Framework: 3.9.2 Ionic App Scripts: 3.1.10 Angular Core: 5.2.11 Angular Compiler CLI: 5.2.11 Node: 8.11.1 OS Platform: Windows 7 Navigator Platform: Win32 User Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36

代码如下:

import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams, MenuController, AlertController } from 'ionic-angular';

@IonicPage()
@Component({
  selector: 'page-terms-and-conditions',
  templateUrl: 'terms-and-conditions.html',
})
export class TermsAndConditionsPage {

  constructor(public navCtrl: NavController,
              public navParams: NavParams,
              public menu: MenuController,
              private alertController: AlertController) {
  }

      showBasicAlert() {
        let basicAlert = this.alertController.create({
          title: 'Ionic alert',
          subTitle: 'ionic alert details',
          buttons: ['OK']
        });
        basicAlert.present();      
  }
}

这是它的HTML:

<ion-header>
    <ion-navbar>
      <ion-title>Alert Controller</ion-title>
    </ion-navbar>
</ion-header>

  <ion-content padding>
    <ion-item-group>
      <ion-item-divider color="light">Basic Alerts</ion-item-divider>
         <button ion-button full (click)="showBasicAlert()">Basic</button>    
    </ion-item-group>
  </ion-content>

这是页面模块:

import { NgModule } from '@angular/core';
import { IonicPageModule, IonicModule } from 'ionic-angular';
import { TermsAndConditionsPage } from './terms-and-conditions';

@NgModule({
  declarations: [
    TermsAndConditionsPage,
  ],
  imports: [
    IonicPageModule.forChild(TermsAndConditionsPage),
    IonicModule
  ],
  exports: [
    TermsAndConditionsPage
  ]
})
export class TermsAndConditionsPageModule {}

我的问题是如何调出AlertController而不出现任何错误? 我是否缺少插件?

0 个答案:

没有答案