2017-12-15 8 views
-2

내 이력 응용 프로그램의 다른 기능에서 경고를 표시하려고합니다. 여기에 내가 무엇을 그리워 않았다, 내가 그것을 클릭하면 함수 내에서다른 기능에서 경고 표시하기

successAlert() { 
this.alertCtrl.create({ 
    title: "Success" 
    }).present(); 
} 

failedAlert() { 
this.alertCtrl.create({ 
    title: "Failed" }).present(); 
} 

하지만, 어떤 경고를 보여주는이 없음을 내 경고가 여기

console.log(response); //return true 
if (response) { 
    this.successAlert; 
} else { 
    this.failedAlert; 
} 

을하고 무엇인가? 여기

UPDATE--

는 이미 this.successAlert();

this.successAlert;을 변경하려고 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(); 
    } 

    } 

의 전체 코드입니다하지만 난이 오류

TypeError: this.successAlert is not a function

답변

2

당신을 얻을 필요하다 paranthesis와 함수를 호출

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

편집 다만,이 같은 화살표 기능을 사용할 필요가 코멘트에 언급 @Suraj Rao 같은

I already try to change this.successAlert; to this.successAlert(); But I get this error: TypeError: this.successAlert is not a function

:

// ...   
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(); 
     } 
    ); 

// ... 
+0

나는이'TypeError : this.suc를 얻는다. cessAlert가 함수가 아닙니다. ' – YVS1102

+0

@ YVS1102는 함수 호출입니다. –

+0

전체 구성 요소 코드를 게시하십시오. – Sajeetharan