我有一个 Angular 5.2.8 应用程序,其中包含 angular-redux/form 6.5.0,当我的表单初始化时出现此错误。
core.js:1448 ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'firstName' of null
TypeError: Cannot read property 'firstName' of null
at Function.State.traverse (state.js:26)
at Function.State.get (state.js:44)
at eval (connect-base.js:92)
at Array.forEach (<anonymous>)
at ReactiveConnect.ConnectBase.resetState (connect-base.js:90)
at eval (connect-base.js:43)
at ZoneDelegate.invoke (zone.js:388)
at Object.onInvoke (core.js:4749)
at ZoneDelegate.invoke (zone.js:387)
at Zone.run (zone.js:138)
at Function.State.traverse (state.js:26)
at Function.State.get (state.js:44)
at eval (connect-base.js:92)
at Array.forEach (<anonymous>)
at ReactiveConnect.ConnectBase.resetState (connect-base.js:90)
at eval (connect-base.js:43)
at ZoneDelegate.invoke (zone.js:388)
at Object.onInvoke (core.js:4749)
at ZoneDelegate.invoke (zone.js:387)
at Zone.run (zone.js:138)
at resolvePromise (zone.js:809)
at eval (zone.js:861)
at ZoneDelegate.invokeTask (zone.js:421)
at Object.onInvokeTask (core.js:4740)
at ZoneDelegate.invokeTask (zone.js:420)
at Zone.runTask (zone.js:188)
at drainMicroTaskQueue (zone.js:595)
at ZoneTask.invokeTask [as invoke] (zone.js:500)
at invokeTask (zone.js:1517)
at HTMLAnchorElement.globalZoneAwareCallback (zone.js:1543)
在我的组件中,我导入了以下内容:
import { FormGroup, FormControl, FormBuilder, Validators } from '@angular/forms';
我像这样初始化我的表单:
this.userForm = this.fb.group({
firstName: ['', [<any>Validators.required]],
lastName: ['', [<any>Validators.required]],
email: ['', [<any>Validators.required, <any>Validators.pattern(this.emailRegex)]],
email2: ['', [<any>Validators.required, <any>Validators.pattern(this.emailRegex)]],
password: ['', [<any>Validators.required, <any>Validators.pattern('((?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{8,50})'), Validators.minLength(6)]],
phone: ['', [<any>Validators.pattern('^[0-9-]{1,20}'), Validators.minLength(10)]],
company: ['', []],
industry: ['', [Validators.required]],
month: ['', []],
day: ['', []],
year: ['', []]
}, {validator: this.matchingEmails('email', 'email2')});
而且我已经确保减速器正确组合。事实上,这种形式可以在不同的开发环境中按预期工作。我尝试将 angular-redux/form 的版本更改为 6.6.0 和 6.7.0,因为它适用于该开发人员(https://github.com/angular-redux/form/issues/53)但不适合我. 任何帮助将不胜感激,谢谢!