0

当设备没有相机时,我想在 Ionic2 上发出警报。

当我启动时:离子服务

然后我尝试显示如下消息:

 let alert = Alert.create({
                title: 'Camera not found',
                subTitle: 'It seems your camera is not working on your device',
                buttons: ['Ok']
            });
            this.nav.present(alert);

我有一个 javascript 错误

Uncaught EXCEPTION: Error during evaluation of "click"
ORIGINAL EXCEPTION: TypeError: rootNav.getActive is not a function
ORIGINAL STACKTRACE:
TypeError: rootNav.getActive is not a function
    at Tab.NavController.present (http://localhost:8100/build/js/app.bundle.js:46996:36)
    at SmartScan.takePicture (http://localhost:8100/build/js/app.bundle.js:60864:23)
    at AbstractChangeDetector.ChangeDetector_SmartScan_0.handleEventInternal (eval at <anonymous> (http://localhost:8100/build/js/app.bundle.js:14578:17), <anonymous>:185:36)
    at AbstractChangeDetector.handleEvent (http://localhost:8100/build/js/app.bundle.js:13892:25)
    at AppView.dispatchEvent (http://localhost:8100/build/js/app.bundle.js:18772:46)
    at AppView.dispatchRenderEvent (http://localhost:8100/build/js/app.bundle.js:18766:22)
    at DefaultRenderView.dispatchRenderEvent (http://localhost:8100/build/js/app.bundle.js:33592:39)
    at eventDispatcher (http://localhost:8100/build/js/app.bundle.js:33258:22)
    at http://localhost:8100/build/js/app.bundle.js:33329:40

在此处输入图像描述

4

4 回答 4

1

在 alert.js 中:

import {Page, Alert, NavController} from 'ionic-angular';

@Page({
templateUrl: 'build/pages/alert/alert.html'
})

export class AlertPage {
    static get parameters() {
        return [[NavController]];
    }
    constructor(nav) {
        this.nav = nav;
    }

    showAlert() {
        let alert = Alert.create({
            title: 'New Friend!',
            subTitle: 'Your friend, Obi wan Kenobi, just accepted your friend request!',
            buttons: ['Ok']
        });
        this.nav.present(alert);

    }
}

在 alert.html 中:

<button block dark (click)="showAlert()">test</button>
于 2016-03-24T18:02:37.357 回答
0

我也在研究ionic2,并且需要在我现有的应用程序中实现“PopUp”窗口。我为此尝试了很多,但没有完成我的任务,最后我做了这样的事情-

  1. pop-up.html
    <button block dark (click)="showAlert()">Help Window</button>

  2. 弹出窗口.ts

    import { Component } from '@angular/core';
    import { Alert, NavController, NavParams} from 'ionic-angular';
    
    @Component({
      templateUrl: 'build/pages/pop-up/pop-up.html',
    })
    
    export class PopUpPage {
        static get parameters() {
          return [[NavController]];
        }
        constructor(private nav: NavController) {
          this.nav = nav;
        }
    
        showAlert() {
          let alert = Alert.create({
            title: 'Help Window!',
            subTitle: 'Mindfulness is here for you and your soul. We are intended to stablish your connection to All Mighty.',
            buttons: ['Cancle']
          });
          this.nav.present(alert);
        }
    }
    

这对我来说很好。

在此处输入图像描述

希望它也对你有用。

于 2016-09-09T09:34:42.973 回答
0

试试这个:

使用这种文件夹和文件的结构

在此处输入图像描述

在:

主页.html

<ion-header>
    <ion-navbar>
        <ion-title>Ionic 2 Notifications</ion-title>
    </ion-navbar>
</ion-header>

<ion-content padding>
    <button block dark (click)="showAlert()">Alert</button>
</ion-content>

在:

主页.ts

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

@Component({
    templateUrl: 'home.html'
})
export class HomePage {

  constructor(public alertCtrl: AlertController) {
  }

  showAlert() {
    let alert = this.alertCtrl.create({
      title: 'New Friend!',
      subTitle: 'Your friend, Obi wan Kenobi, just accepted your friend request!',
      buttons: ['OK']
    });
    alert.present();
  }

}

我从文档站点获得了这些信息: https ://ionicframework.com/docs/v2/components/#action-sheets

于 2017-02-06T13:21:15.073 回答
-1

好像还没准备好...

调查代码

        this.nav.present(alert);

它在这里传递并返回:

if (rootNav['_tabs']) {
                // TODO: must have until this goes in
                // https://github.com/angular/angular/issues/5481
                void 0;
                return;
            }
于 2016-03-25T12:29:51.030 回答