I have a input field and a button.When the field is not empty the button should be enabled.But here in my case i am already passing input value.so it should be enabled but this is not happening.It is being enabled when i type anything in the input field.Any info on how to achieve it.below is my code
export class SignupFormComponent implements OnInit {
userForm: FormGroup;
submitted: boolean;
hello = "hello world";
ngOnInit() {
this.userForm = new FormGroup({
firstName: new FormControl('',[<any>Validators.required, <any>Validators.minLength(5)])
});
}
onSubmit({ value, valid }: { value: userForm, valid: boolean }) {
this.submitted = true;
console.log(value,valid);
}
}
here is my html code
<form [formGroup]="userForm" (ngSubmit)="onSubmit(userForm)" validate>
<div class="form-group">
<label>First Name</label>
<input type="text" class="form-control" formControlName="firstName" [value]="hello">
</div>
<button type="submit" class="btn btn-primary" [disabled]="userForm.invalid">Submit </button>
</form>