gpt4 book ai didi

src/app/reactive-form/reactive-form.component.html:47:48 - error TS2531: Object is possibly 'null'. src/app/reactive-form/reactive-form.component.ts(Src/app/reactive-form/reactive-form.component.html:47:48-错误TS2531:对象可能为‘Null’。Src/app/reactive-form/reactive-form.component.ts)

转载 作者:bug小助手 更新时间:2023-10-25 19:36:58 31 4
gpt4 key购买 nike



Object is possibly 'null'. Element implicitly has an 'any' type because expression of type '"controls"' can't be used to index type 'AbstractControl<any, any>'.


Property 'controls' does not exist on type 'AbstractControl<any, any>'.

类型‘AbstractControl ’上不存在属性‘Controls’。


<div class="form-group" formArrayName="skills">
<ng-container *ngFor="let skill of reactiveForm.get('skills')['controls']; let i = index;">
<label for="Skills">Skills</label>
<input type="text">
</ng-container>
</div>

ts file


reactiveForm!: FormGroup;
ngOnInit(): void {
this.reactiveForm = new FormGroup({
// To set default value we need to pass this value instead of null.
firstname: new FormControl(null, Validators.minLength(4)),
lastname: new FormControl(null, Validators.required),
email: new FormControl('[email protected]', [Validators.required, Validators.email]),
country: new FormControl('Canada'),
gender: new FormControl('male'),
hobbies: new FormControl(null),
skills: new FormArray([
new FormControl(null),
])
})
}

onSubmit() {
console.log(this.reactiveForm);
}
}

更多回答

You have the same question (with the solution) in this SO. Please, before ask a question try look for if there a similar question yet answered. (the SO it's the question suggested in "related question"

你在这件事上也有同样的问题(关于解决方案)。请在问问题之前,试着寻找是否有类似的问题已经得到了回答。(所以这是“相关问题”中提出的问题。

优秀答案推荐
更多回答

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com