angularjs FormGroup有效值为true,但返回false



 this.loginForm = new FormGroup({
      'phone': new FormControl(this.loginer.phone, [
        Validators.required,
        validateMobile
      ]),
      'password': new FormControl(this.loginer.password,[
        Validators.required
      ]),
  })
  public formChange(){
    console.log(this.loginForm);
    console.log(this.loginForm.valid);
  }





javascript - angularjs FormGroup有效值为true,但返回false-LMLPHP

javascript - angularjs FormGroup有效值为true,但返回false-LMLPHP

最佳答案

尝试这个 :

import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';

export class AppComponent implements OnInit {
    loginForm: FormGroup;
    constructor(private formBuilder: FormBuilder) {
        this.loginForm = this.formBuilder.group({
            phone: [null, Validators.compose([Validators.required])],
            password: [null, Validators.compose([Validators.required])]
        })
    }

    ngOnInit() {
        console.log(this.loginForm);
        console.log(this.loginForm.valid);
    }
}


javascript - angularjs FormGroup有效值为true,但返回false-LMLPHP

10-08 08:37