Angular Redux-Form初始化错误:TypeError:无法读取null属性

时间:2018-03-23 19:49:55

标签: angular redux redux-form angular-forms angular-redux

我有一个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)但不适合我。任何帮助都将非常感谢,谢谢!

0 个答案:

没有答案