我正在根据从 API 收到的 JSON 数据在 Angular 中动态创建反应式表单。有时表单只有几个表单控件,但有时有很多表单组或带有表单组的表单数组。
我有一个关于带有多个 FormGroup 的 FormArray 的问题。在这个 FormGroups 中,一些 FormControl 可能是必需的,有些则不是。但不需要整个 FormGroup。只有当组中的某些FormControls被编辑后,整个表单组必须有效(每个需要的FormControl不能为空)。
所以我的问题是如何为整个 FormGroup 创建自定义验证器,这将确保如果这些具体组中的每个 FormControl 都为空,则该组将有效。但是,例如,如果要编辑一个 FormControl,则必须填写每个必需的 FormControl。
非常感谢您的想法。
在我的计算机上安装 angular/cli 时我遇到了一个小问题。我已经安装了 Node.js 的最新稳定版本(当前是 v. 10.16.0 和 npm 6.9.0)。安装成功完成,没有任何问题。
安装后,我尝试在命令提示符下安装 angular/cli,但出现此错误。
npm ERR! code E400
npm ERR! 400 Bad Request - GET https://registry.npmjs.org/@angular%2fcli
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\h053z9rc\AppData\Roaming\npm-cache\_logs\2019-07-09T05_03_06_062Z-debug.log
Run Code Online (Sandbox Code Playgroud)
在日志文件中是这些信息
0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'install',
1 verbose cli '-g',
1 verbose cli '@angular/cli' ]
2 info using npm@6.9.0
3 info using …Run Code Online (Sandbox Code Playgroud)