Angular6 httpclient has already assigned a value to the field, why does the field always undefined?

has been executed to the yellow part, res ["data"] .itemMaterialType = 3,
this.itemMaterialType= res [" data"] .itemMaterialType; this sentence has been executed, why this.itemMaterialType has always been the theoretical this.itemMaterialType=3 of undefined;.

the following is the encapsulation method,

  async searchData() {
    this.itemMaterialType = "4";
    await this.api.Dispatch.queryProcessDetailByProcessId({
      processId: this.processId
    })
      .then(res => {
        this.data = res["data"];
        this.isFeedMaterial = res["data"].isFeedMaterial.toString();
        this.itemMaterialType = res["data"].itemMaterialType;
      });
  }
    queryProcessDetailByProcessId: async (option) => await this.http.getByPromise("/api/ScheduleProcess/GetProcessDetail", option),
  async getByPromise(url: string, params: {}) {
    return await this.http.get(this.domain + url, { observe: "body", params: params })
      .toPromise();
  }
The

this context has changed. You can print out the this and see where it points.


Why do you bring then,


when you use sync await,?

1. Then after getting the data, there is no need to use async await

2 after obtaining the res, you can directly use the abbreviation to use the dot syntax res.data

.

3 resolve after conversion to promise in api (data) reject (cache Error) does not need to be forced to be converted to Synchronize


browser illusion that what is printed on the console is not necessarily real. Sometimes bug, appears in this, but there is no problem with using it in the code. If there is a problem when using the code, you can find the reason again


VS code debugging status this has always been undefined, but the data that is running normally can also be displayed; debugging with the browser found that this is also normal; pit

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bf2288-31dbb.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bf2288-31dbb.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?