我将项目迁移到 Angular 15,无法再直接使用 FormsBuilder 来实现响应式表单。我收到一个未定义的异常:
ERROR Error: Uncaught (in promise): TypeError: Cannot read properties of undefined (reading 'group')
TypeError: Cannot read properties of undefined (reading 'group')
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
settingsForm = this.formBuilder.group({
locations: ''
});
constructor(private formBuilder: FormBuilder) {}
Run Code Online (Sandbox Code Playgroud)
之前一切都很好。一个有效的解决方案是通过生命周期钩子 NgOnInit。然而,这将是不推荐的方式,我会失去隐式打字。
可能是什么原因?