作者:手机用户2502914831 | 来源:互联网 | 2023-02-06 02:41
我有一个包含FormGroups的FormArray的以下表单
0">
{{screenForm.controls.iPhoneScreenshots?.length }}
url值来自一个数组,该数组在回调中通过API填充我设置的值:
private setScreenShots(app: ItunesApp): void {
if (app.hasOwnProperty('screenshotUrls')) {
const screenShots = app.screenshotUrls.map(url => {
return this.fb.group({
url: [url, Validators.required]
});
}
);
const screenShotsArray = this.fb.array(screenShots);
this.screenForm.setControl('iPhoneScreenshots', screenShotsArray);
}
}
初始数组为空
private createForm() {
this.appSiteForm = this.fb.group({
title: ['', Validators.required]
});
this.screenForm = this.fb.group({
iPhoneScreenshots: this.fb.array([]),
});
}
这段代码对我来说很奇怪
img src="{{app.screenshotUrls[i]}}"
我这样做是因为url.value()或url.get('value')会引发错误.
那么如何访问表单控件的值呢?
1> yurzui..:
您可以尝试从url组获取控制权
Plunker示例
2> Moshe..:
尝试这个:
screenForm.get('url').value
如果这不起作用,我将不得不查看您的整个表单构建器以提供进一步的帮助。