首页 新闻 会员 周边 捐助

Angular: Strongly Typed Reactive Forms 不能正常工作

0
悬赏园豆:30 [已解决问题] 解决于 2025-05-10 22:57

下面使用 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],
        });
    }
}
dudu的主页 dudu | 高人七级 | 园豆:24691
提问于:2025-05-10 22:39
< >
分享
最佳答案
0

是 editLinkForm 的类型被定义为 FormGroup 引起的,改为 editLinkForm = this.createFormGroup() 自动推断类型就行了

智能提示的效果

dudu | 高人七级 |园豆:24691 | 2025-05-10 22:55
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册