下面使用 reactive forms 的 代码,在 vscode 编辑器中输入 this.editLinkForm.value.
无任何智能提示,正常情况下应该出现在 createFormGroup 中定义的 categoryId, title, url
export class LinksMainComponent extends LinksBaseComponent implements OnInit {
editLinkForm: FormGroup;
constructor(
private fb: FormBuilder,
) {
this.editLinkForm = this.createFormGroup();
}
private createFormGroup() {
return this.fb.nonNullable.group({
categoryId: ['', linkDtoValidators.categoryId],
title: ['', linkDtoValidators.title],
url: ['', linkDtoValidators.url],
});
}
}
是 editLinkForm 的类型被定义为 FormGroup 引起的,改为 editLinkForm = this.createFormGroup()
自动推断类型就行了
智能提示的效果