Angular 如何显示在ionic 3 API调用中获得的纯文本值

Angular 如何显示在ionic 3 API调用中获得的纯文本值,angular,typescript,ionic2,ionic3,Angular,Typescript,Ionic2,Ionic3,您好,我在爱奥尼亚3中制作了一个注册应用程序,我试图实现的是,我正在进行一个API调用,我正在发布数据,然后我得到一个响应,然后我想在警报中显示它,然后重定向页面 这是我的register-user.html <ion-header> <ion-navbar hideBackButton color="title"> <ion-title text-center>Register</ion-title> </i

您好,我在爱奥尼亚3中制作了一个注册应用程序,我试图实现的是,我正在进行一个API调用,我正在发布数据,然后我得到一个响应,然后我想在警报中显示它,然后重定向页面

这是我的register-user.html

<ion-header>
    <ion-navbar hideBackButton color="title">
        <ion-title text-center>Register</ion-title>
    </ion-navbar>
</ion-header>
<ion-content class="content">
        <ion-grid>
            <ion-row>
              <ion-col col-12 ion-fixed>
                <ion-list>
                    <ion-card>
                        <ion-card-header>
                            <ion-img class="logo" alt="logo" [src]="myImage"></ion-img>
                        </ion-card-header>
                        <ion-card-content>
                            <ion-item>
                                <ion-label floating>Full Name</ion-label>
                                <ion-input autocomplete="on" type="text" #name></ion-input>
                            </ion-item>
                            <ion-item>
                                <ion-label floating>Email-ID</ion-label>
                                <ion-input autocomplete="on" type="email" #email></ion-input>
                            </ion-item>
                            <ion-item>
                                <ion-label floating>Mobile Number</ion-label>
                                <ion-input autocomplete="on" type="number" #mobile></ion-input>
                            </ion-item>
                            <ion-item>
                                <ion-label floating>Company Name</ion-label>
                                <ion-input autocomplete="on" type="text" #companyName></ion-input>
                            </ion-item>
                            <ion-item class="mpin">
                                <ion-label text-center floating><b>MPIN</b></ion-label>
                                <ion-input text-center type="password" #mpin></ion-input>
                            </ion-item>
                            <ion-item class="proceedButton">
                                <button ion-button large color="secondary" outline padding strong round (click)="register()">&nbsp;<ion-icon name="arrow-forward"></ion-icon>&nbsp;</button>
                            </ion-item>
                            <ion-item>
                                <button ion-button large color="primary" outline padding block round (click)="home()">Registered? Login Now!</button>
                            </ion-item>
                        </ion-card-content>
                    </ion-card>
                </ion-list>
               </ion-col>
            </ion-row>
        </ion-grid>
</ion-content>
我得到的响应是:{“msg”:“success”,“msg”:“user registed”}

我还试图显示this.data.response.msg


仍然没有成功,我还遇到了一个问题,当我第一次单击按钮时,警报窗口没有显示任何值。但是,当我第二次再次单击提交按钮时,它会显示响应值为什么?我哪里错了?

您需要解析响应,如下所示:

this.http.post(link, myData)
    .map(response => response.json()) // <--- Here!
    .subscribe(data => {

        // The "data" property is now the body, 
        // so you can access to it as an object

        this.data.response = data; 

    }
this.http.post(link,myData)
.map(response=>response.json())//{
//“数据”属性现在是主体,
//因此,您可以将其作为对象访问
this.data.response=数据;
}
this.http.post(link, myData)
    .map(response => response.json()) // <--- Here!
    .subscribe(data => {

        // The "data" property is now the body, 
        // so you can access to it as an object

        this.data.response = data; 

    }