TypeError:无法在setUpControl的字符串“ [email protected]”上创建属性“ validator”

Gunjan Patel:

我在遇到问题formGroup首先,我基于URL,我取了一些价值,并调用了API,以检索特定用户数据以获取预字段文本。

register.html

<form [formGroup]="form" (ngSubmit)="onSubmit(form.value)" class="form-horizontal">
    <div class="form-group row">
        <label for="inputEmail3" class="col-sm-4 ">Username</label>
        <div class="col-sm-8">
            <input [formControl]="email" type="text" class="form-control" id="inputEmail3" placeholder="Email Address" [readonly]="isReadOnly">
        </div>
    </div>
</form>

register.component.ts

import { Component } from '@angular/core';
import { FormGroup, AbstractControl, FormBuilder, Validators } from '@angular/forms';
import { Router, ActivatedRoute } from '@angular/router';
import { EmailValidator, EqualPasswordsValidator } from '../../theme/validators';

@Component({
  selector: 'register',
  templateUrl: './register.html',
})
export class Register {
  public form: FormGroup;
  public email: AbstractControl;
  public username: string;

  constructor(private registerService: RegisterService, fb: FormBuilder, private router: Router, private route: ActivatedRoute) {
    this.form = fb.group({
      'email': ['', Validators.compose([Validators.required])]
      .... etc..
    });

    this.email = this.form.controls['email'];

    this.registerService.getUser({ userId: "asdasd2123da2das" }).subscribe(posts => {
      if (posts) {
          var userObj = posts.json();
          console.log("userObj : ", userObj.data);
          if (userObj.data && userObj.data[0].email) {
            this.email = this.username = userObj.data[0].email;  // ouput : [email protected]
            this.isReadOnly = true;
            this.router.navigateByUrl('/register');
          } else {
            alert("You are Not Autorize to access this Page");
            this.router.navigateByUrl('/login');
          }
        }
    });

  }
}

错误详情 :

TypeError: Cannot create property 'validator' on string '[email protected]'
    at setUpControl (http://localhost:3004/vendor.dll.js:9739:23)
    at FormControlDirective.ngOnChanges (http://localhost:3004/vendor.dll.js:44196:89)
    at Wrapper_FormControlDirective.ngDoCheck (/ReactiveFormsModule/FormControlDirective/wrapper.ngfactory.js:50:18)
sainu:
<form [formGroup]="form" (ngSubmit)="onSubmit(form.value)" class="form-horizontal">
        <div class="form-group row">
            <label for="inputEmail3" class="col-sm-4 ">Username</label>
            <div class="col-sm-8">
                <input formControlName="email" type="text" class="form-control" id="inputEmail3" placeholder="Email Address" [readonly]="isReadOnly">
            </div>
        </div>
</form>

请尝试将此更改[formControl]formControlName

并将输出设置为输入字段,请执行以下操作,将线指向 this.form.patchValue

import { Component } from '@angular/core';
import { FormGroup, AbstractControl, FormBuilder, Validators } from '@angular/forms';
import { Router, ActivatedRoute } from '@angular/router';
import { EmailValidator, EqualPasswordsValidator } from '../../theme/validators';

@Component({
  selector: 'register',
  templateUrl: './register.html',
})
export class Register {
  public form: FormGroup;
  public email: AbstractControl;
  public username: string;

  constructor(private registerService: RegisterService, fb: FormBuilder, private router: Router, private route: ActivatedRoute) {
    this.form = fb.group({
      'email': ['', Validators.compose([Validators.required])]
      .... etc..
    });

    this.email = this.form.controls['email'];

    this.registerService.getUser({ userId: "asdasd2123da2das" }).subscribe(posts => {
      if (posts) {
          var userObj = posts.json();
          console.log("userObj : ", userObj.data);
          if (userObj.data && userObj.data[0].email) {
            this.email = this.username = userObj.data[0].email;  // ouput : [email protected]
            this.form.patchValue({
                email : this.email
             });

            this.isReadOnly = true;
            this.router.navigateByUrl('/register');
          } else {
            alert("You are Not Autorize to access this Page");
            this.router.navigateByUrl('/login');
          }
        }
    });

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

收到错误“ TypeError:无法在字符串'control'上创建属性'validator'”

无法使用组件工厂在字符串“ userForm”上创建属性“ validator”

使用gmail的Nodemailer,无法在字符串“ SMTP”上创建属性“ mailer”

Angular TypeError:无法在字符串''上创建属性

TypeError:无法在字符串“ /:id”上创建属性“ next”

未被捕获的TypeError:无法在字符串'上创建属性'guid'

未捕获的TypeError:无法在字符串“ wtd_background_image”上创建属性“ style”

未被捕获的TypeError:无法在字符串“”上创建属性“ empFirstName”

类型错误:无法在字符串 'a' 上创建属性 'style'

无法在字符串 '' 上创建属性 'fillColor'

错误TypeError:“无法在“ signUpForm”上分配给属性“ validator”:不是对象”

“无法分配给“formControlAnimalSelect”上的属性“validator”:不是对象”Angular Typescript

asp.net '无法绑定多部分标识符“[email protected]”。

TS2511:无法创建抽象类“ Validator”的实例

jQuery Validator在选择下拉列表上无法正常工作

通过abc创建每种可能的字符串组合

express-openapi-validator:错误:TypeError:无法读取未定义的属性“模式”

无法在字符串'__zone_symbol__optimizedZoneEventTask'上创建属性'__creationTrace__'

无法在字符串“ Information Technology” angularjs上创建“ selected”属性

TypeError:无法在字符串上创建属性“ _id”

JS错误,未捕获的TypeError:无法读取未定义的属性“子字符串”

迭代字符串数组:TypeError:无法读取未定义的属性“ 0”

由于TypeError无法创建索引:格式字符串的参数不足

Browserify无法使用babelify转换创建捆绑包(TypeError:路径必须为字符串。)

TypeError:无法在re.findall()中的类似字节的对象上使用字符串模式

Python 3.6 Googleads TypeError:无法在类似字节的对象上使用字符串模式

TypeError:无法在类似字节的对象上使用字符串模式

re.search()。TypeError:无法在类似字节的对象上使用字符串模式

TypeError:无法在类似字节的对象上使用字符串模式