我無法理解以下內容:
我有這堂課:
export class PatientOverviewColumnConfig {
public Id!:number;
public ColumnField!:string
public Priority!:number;
public UserId!:number;
public IsHidden!:boolean;
}
還有這個:
export class UserClientConfiguration {
public patientOverviewColumnConfig: PatientOverviewColumnConfig[];
constructor(){
this.patientOverviewColumnConfig = [];
}
}
我有一項服務是從 sql server 檢索資料:
export class ClientconfigurationService {
static instance : ClientconfigurationService;
apiUrl?:string;
public patientOverViewColumns:PatientOverviewColumnConfig[]
public columns!:PatientOverviewColumnConfig[]
constructor(appConfig:AppConfigService,private http: HttpClient) {
if(!ClientconfigurationService.instance){
ClientconfigurationService.instance = this;
}
this.apiUrl = appConfig.data.API_URL;
this.patientOverViewColumns = this.getColumns();
return ClientconfigurationService.instance;
}
async getColumns():Promise<PatientOverviewColumnConfig[]>{
const url = this.apiUrl '/ColumnConfig/GetColumnConfiguration'
const response = this.http.get<PatientOverviewColumnConfig[]>(url)
this.columns = await lastValueFrom(response);
return this.columns;
}
}
我收到以下錯誤:“Promise<PatientOverviewColumnConfig[]>”型別缺少“PatientOverviewColumnConfig[]”型別中的以下屬性:長度、彈出、推送、concat 等 28 個。
我錯過了什么?我應該修改 this.columns 因為它是一個承諾?
uj5u.com熱心網友回復:
您不能直接分配異步回傳值。
更改此行:
this.patientOverViewColumns = this.getColumns();
至
this.getColumns().then(result => this.patientOverViewColumns = result);
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/529965.html
標籤:有角度的打字稿