angular HttpClient getbyid 方法获取数据

2021-05-23 08:28

阅读:433

标签:logs   primary   技术分享   取数   结果   col   this   client   inf   

续上一篇之后,简单传参的方法,最常用的是getbyid 方法。

直接上代码:

getbyId(id: string) {
    this.myhttp.get(‘http://192.168.2.139:9002/api/patients/‘ + id)
      .subscribe(data => {
        this.myPatient = new Patient({
          id: data[‘PatientId‘],
          FirstName: data[‘Details‘].FirstName,
          LastName: data[‘Details‘].LastName,
          MiddleName: data[‘Details‘].MiddleName,
          BirthDate: data[‘Details‘].BirthDate,
          Gender: data[‘Details‘].Gender,
          PhoneNumber: data[‘PersonalInfo‘].PhoneNumberPrimary,
          ZIPCODE: data[‘PersonalInfo‘].ZIPCODE,
          City: data[‘PersonalInfo‘].City,
          Street: data[‘PersonalInfo‘].Street,
          EmailAddress: data[‘PersonalInfo‘].EmailAddressPrimary,
          CitizenServiceNumber: data[‘PersonalInfo‘].ServiceNumber
        });
      });
  }

前台:

div>
    button (click)="getbyId(‘a6c804e8-daef-42fb-8cd2-c56a02540d2c‘)"> getbyId:a6c804e8button>
    div *ngIf=myPatient>
      ul>
        li>id:{{myPatient.id}}li>
        li>FirstName :{{myPatient.FirstName}} li>
        li>email:{{myPatient.EmailAddress}}li>
      ul>
    div>
  div>

显示结果:

技术分享

其它方法,待续。。。

angular HttpClient getbyid 方法获取数据

标签:logs   primary   技术分享   取数   结果   col   this   client   inf   

原文地址:http://www.cnblogs.com/cxd1008/p/7686164.html


评论


亲,登录后才可以留言!