2016-02-05 4 views
0

Я хотел бы поднять оповещение на Ionic2, если устройство не имеет камеры.ionic 2 Alert не работает на веб-странице

Когда я запуск: ионный служат

тогда я пытаюсь отобразить сообщение следующим образом:

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); 

У меня есть яваскрипта ошибка

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 

enter image description here

+0

ли этот код работает в Mobile строит ..? .Пожалуйста, уточните –

ответ

-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; 
      } 
+1

. Пожалуйста, уточните свой ответ .. он решает вашу ошибку. –

1

В боевой готовности .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> 
0

Я также работаю над ionic2 и нуждаюсь в реализации окна «PopUp» в моем существующем приложении. Стараюсь много для, что, не получить мою задачу выполненной, наконец, я сделал что-то вроде this-

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

  2. поп-up.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); 
        } 
    } 
    

И это отлично работает для меня.

enter image description here

Надеется, что это будет работать для вас тоже.

0

Попробуйте это:

с этой структурой папок и файлов

enter image description here

В:

home.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> 

В:

дом.ц

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