我想在 Angular 中制作一个下拉按钮。 当我在项目中使用此 {{ getFiscalYears.Title }} 代码时,我遇到了以下错误:
Uncaught TypeError: Cannot read properties of null
组件.html:
<div *ngIf="userInfo" class="dropdown">
<button class="btn dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">FicialYears {{ userInfo.ActiveYearTitle }}</button>
<div *ngIf="getFiscalYears" class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item">{{ getFiscalYears.Title }}</a>
</div>
</div>
组件.ts:
userInfo: ImidroProductivityModel.UserInfoDto;
getFiscalYears: ImidroProductivityModel.FiscalYearDto;
contex.d.ts
declare module ImidroProductivity.Model.Dto {
class FiscalYearDto extends $data.Entity {
Id: string;
static Id: any;
Title: number;
static Title: any;
}
}
http.service.ts:
async getFiscalYears(): Promise<ImidroProductivityModel.FiscalYearDto[]> {
try {
var context = await this.getContext();
return await context.form.getFiscalYears().toArray();
}
catch (err) {
throw err;
}
}
从服务器加载 getFiscalYears 时是否有可能在短时间内为空?
如果将其更改为 {{ getFiscalYears?.Title }} 有效吗?
您可能希望将数据加载到角度解析器中,以便在尝试渲染页面之前拥有所需的所有网络资源。