Skip to content

Instantly share code, notes, and snippets.

@DaveMBush
Last active April 15, 2017 20:55
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save DaveMBush/58c2d6bf41fdb255e4582f35134665a1 to your computer and use it in GitHub Desktop.
Angular(2+) Model Driven Forms Are Superior
this.form.patchValue({
name: contact.name,
sex:contact.sex,
dob:contact.dob.toLocaleDateString()
});
this.form.valueChanges.subscribe((value)=>{
this.contact = deepAssign({},this.contact,value);
});
<form [formGroup]="form" >
<input formControlName="name">
</form>
this.form = formBuilder.group({
name: ['',Validators.required],
sex: ['',Validators.required],
dob: ['',
Validators.compose([ Validators.required, View.isDate])]
});
<form #form="ngForm">
<input name="name" type="text" [(ngModel)]="nameField" >
</form>
@DaveMBush
Copy link
Author

This is code for an article on my blog (http://blog.dmbcllc.com) by the same name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment