angularjs FormGroup valid为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);
}

答案 0 :(得分:1)
试试这个:
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);
}
}