Javascript 显示来自其他功能的警报

Javascript 显示来自其他功能的警报,javascript,angular,ionic3,Javascript,Angular,Ionic3,我正在尝试在我的ionic应用程序中显示来自其他功能的警报。我就是这么做的 console.log(response); //return true if (response) { this.successAlert; } else { this.failedAlert; } 这是我的警告,内部功能 successAlert() { this.alertCtrl.create({ title: "Success" }).present(); } failedAlert()

我正在尝试在我的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:this.successAlert不是函数


您需要使用paradensis调用函数

if (response) {
  this.successAlert();
} else {
  this.failedAlert();
}

编辑

我已经尝试更改
this.successAlert;到这个。successAlert()
正如评论中提到的,您需要使用箭头函数,如下所示:

// ...          
this.http.post('http://192.168.3.223:84/fppb/andro_login',this.loginData)
    .subscribe(
       (response) => { // <---- Here!
            console.log(response);
            if(response) {
                this.successAlert();
            }   
            else {
                this.failedAlert();
            }
        },
        (error) => { // <---- And here as well
             this.failedAlert();
        }
     );

// ...
/。。。
this.http.post('http://192.168.3.223:84/fppb/andro_login”,这是loginda)
.订阅(

(response)=>{//{//我得到了这个
类型错误:this.successAlert不是一个函数
@YVS1102
函数(response)
使用箭头函数。这里还有
函数(错误)