问题是我想在警报(按钮)中创建一个事件,我想让它移动到另一个页面,这个按钮不再存在于HTML中,因为我无法创建(点击)功能当我运行它时,不要给我任何提供程序错误"没有NavController的提供程序"。 我尝试了另一种选择
我使用了ViewChild
并从@angular/core
中导入了它
制作@viewChild('myApp')
并将此#myApp
添加到ion-nav
在课堂上定义navCtrl: NavController
。
在构造函数中,我添加了public push: Push
,但它无法读取它。
在这段时间里它给了我"无法读取属性' navCtrl' of null"。
import { Component } from '@angular/core';
import { Platform, Alert, AlertController, NavController } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import firebase from 'firebase';
import { FirebaseProvider } from '../providers/firebase/firebase';
import { ViewProvider } from '../providers/view/view';
//pages
import { OpenPage } from '../pages/open/open';
import { AcceptOrderPage } from '../pages/accept-order/accept-order';
@Component({
templateUrl: 'app.html'
})
export class MyApp {
rootPage = OpenPage;
public marginClass:any="normal";
public available:boolean=true;
public orderId:string;
public alert: Alert;
constructor(platform: Platform, statusBar: StatusBar, splashScreen:
SplashScreen, public fb: FirebaseProvider,
public view: ViewProvider, private alertCtrl: AlertController, public
navCtrl: NavController) {
platform.ready().then(() => {
if (platform.is('ios')){
this.marginClass="iosMargin"
}
statusBar.styleDefault();
splashScreen.hide();
});
var config = {
apiKey: "AIzaSyDbn0bLyNh4emJXjVAKb_BsOyH7ahiY-3U",
authDomain: "cat-drivers.firebaseapp.com",
databaseURL: "https://cat-drivers.firebaseio.com",
projectId: "cat-drivers",
storageBucket: "cat-drivers.appspot.com",
messagingSenderId: "444330551162"
};
firebase.initializeApp(config);
var starCountRef =
firebase.database().ref('drivers/'+this.orderId+'/Orders');
starCountRef.on('value', function(snapshot) {
let alert = alertCtrl.create({
title: 'لديك طلب جديد؟',
buttons: [
{
text: 'رفض',
role: 'cancel',
handler: () => {
console.log('Cancel clicked');
}
},
{
text: 'قبول',
handler: () => {
console.log('Buy clicked');
navCtrl.push(AcceptOrderPage);
}
}
]
});
alert.present();
});
}
sendData(x){
this.view.localGet("uid").then((uid)=>{
this.fb.setData('drivers/'+uid+'/outOfService/',x)})
}
toggleState(item){
this.available=!this.available;
// console.log(this.available)
}
}
答案 0 :(得分:0)
请检查此代码:
var starCountRef =
firebase.database().ref('drivers/'+this.orderId+'/Orders');
var _that=this;
starCountRef.on('value', function(snapshot) {
let alert = alertCtrl.create({
title: 'لديك طلب جديد؟',
buttons: [
{
text: 'رفض',
role: 'cancel',
handler: () => {
console.log('Cancel clicked');
}
},
{
text: 'قبول',
handler: () => {
console.log('Buy clicked');
_that.navCtrl.push(AcceptOrderPage);
}
}
]
});
alert.present();