Skip to content

Instantly share code, notes, and snippets.

@azanebrain
Last active March 8, 2018 19:57
Show Gist options
  • Save azanebrain/235434719a324bada0cf538763f21df1 to your computer and use it in GitHub Desktop.
Save azanebrain/235434719a324bada0cf538763f21df1 to your computer and use it in GitHub Desktop.
export interface MyFormValues {
captcha: number;
password: string;
username: string;
}
export interface MyForm extends FormGroup {
value: MyFormValues;
controls: {
captcha: AbstractControl;
password: AbstracControl;
username: AbstracControl;
}
}
///
public myForm: MyForm
constructor(private formBuilder: FormBuilder) { }
ngOnInit() {
this.myForm: MyForm = this.formBuilder.group({
captcha: ['', Validators.required],
usepasswordrname: ['', Validators.required],
username: ['', Validators.required],
})
this.myForm.us // Now the 'username' property will be suggested
this.myForm.value.fakeControl // This will generate an error to make sure you don't try and access non-existent properties
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment