angular - 错误类型错误:this.homeboxsp.map 不是 patchForm 中的函数
问题描述
我的代码中有这个patchForm:
populateForm() {
this.hsP.homeboxPGetAll().subscribe(
homeboxsp => {
this.homeboxsp = homeboxsp
let controls = {
'homeboxpackage_id': new FormControl('', Validators.required)
};
for (let i = 0; i < this.homeboxsp.length; i++) {
controls['active-' + this.homeboxsp[i].homeboxpackage_id] = new FormControl(this.homeboxsp[i].active === 1, Validators.required)
}
this.activeHomeboxPForm = new FormGroup(controls);
this.patchForm();
}
)
}
patchForm() {
this.activeHomeboxPForm.patchValue({
homeboxpackage_id: this.homeboxsp.map(x => x.homeboxpackage_id),
});
}
服务.ta
public homeboxPGetAll(): Observable<HomeboxP[]> {
let headers = new Headers();
headers.append('x-access-token', this.auth.getCurrentUser().token);
return this.http.get(Api.getUrl(Api.URLS.homeboxPGetAll), {
headers: headers
})
.map((response: Response) => {
let res = response.json();
if (res.StatusCode === 1) {
this.auth.logout();
} else if (res.StatusCode === 4) {
return false;
} else if (res.StatusDescription === 'No result') {
return false;
} else {
return res.StatusDescription.map(homeboxP => {
return new HomeboxP(homeboxP);
});
}
});
}
当 API 获取数据时,不会显示此错误。当 API 在控制台中获取空数据时显示此错误:
错误类型错误:this.homeboxsp.map 不是 HomeboxComponent.patchForm 中的函数
你能问我任何想法,如何解决这个错误?
解决方案
推荐阅读
- android - 实施来电筛选服务
- postgresql - 列出所有活动(即尚未提交)事务的事务时间戳(transaction_timestamp())
- java - 获取 MongoCommandException:命令失败,错误 18(AuthenticationFailed):“身份验证失败。” 在服务器本地主机上:27017
- python - 从 Python 中的列表列表创建字典列表
- java - 如何从视图中获取文本,而不是 Textview
- java - 从 XML 中的数组中获取单个字符串
- .net - 将程序集加载到 SQL Server 2017 数据库中
- .htaccess - 如何在子域上配置 Codeigniter 网站的副本?
- r - ggplot2 使用 facetscales 包更改每个单独的 facet 面板的日期轴限制
- json - 我想获取数据包含 json 数据字段中的字符串