1. 程式人生 > >angular HttpClient getbyid 方法獲取數據

angular HttpClient getbyid 方法獲取數據

方法 ast tizen email image sub es2017 color name

續上一篇之後,簡單傳參的方法,最常用的是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:a6c804e8</button>
    <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 方法獲取數據