我正在尝试在我的ionic应用程序中显示来自其他功能的警报。我就是这么做的
console.log(response); //return true
if (response) {
this.successAlert;
} else {
this.failedAlert;
}
这是我的警告
successAlert() {
this.alertCtrl.create({
title: "Success"
}).present();
}
failedAlert() {
this.alertCtrl.create({
title: "Failed" }).present();
}
但当我单击它时,没有显示警报,我错过了什么?
更新--
以下是的完整代码
home.ts
import { Component, ViewChild } from '@angular/core';
import { NavController, App ,LoadingController,AlertController } from 'ionic-angular';
import { BrowserModule } from '@angular/platform-browser';
import { HttpClient, HttpHeaders,HttpClientModule } from '@angular/common/http';
import { Events } from 'ionic-angular';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
loginData = {};
constructor(public navCtrl: NavController,
public app: App,
public ld: LoadingController,
public http:HttpClient,
public alertCtrl: AlertController,
public events: Events
) {
}
signIn(){
let loader = this.ld.create({ content: "Please wait..." });
// loader.present();
var headers = {
'Access-Control-Allow-Origin' : '*',
'Access-Control-Allow-Methods' : 'POST'
};
let bodyString = JSON.stringify(this.loginData);
this.http.post('http://192.168.3.223:84/fppb/andro_login',this.loginData)
.subscribe(
function(response) {
console.log(response);
if(response)
{
this.successAlert();
}
else {
this.failedAlert();
}
},
function(error) {
this.failedAlert();
}
);
}
successAlert() {
this.alertCtrl.create({
title: "Success",
subTitle: '10% of battery remaining',
buttons: ['Dismiss']
}).present();
}
failedAlert() {
this.alertCtrl.create({
title: "Failed" }).present();
}
}
我已经试着改变了
this.successAlert;
到
this.successAlert();
但我得到了这个错误
TypeError:此。successAlert不是一个函数