×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: Nilesh Yadav
Added: Jun 14, 2017 8:09 PM
Views: 10
Tags: no tags
two way data binding is not possible in model driven forms
  1. import {FormGroup, FormControl} form '@angular/forms';
  2.  
  3.  
  4. export class AppComponent {
  5.         userForm = new FormGroup({
  6.           name : new FormControl('Nilesh'),
  7.           email: new FormControl(),
  8.           address : new FormGroup({
  9.           city: new FormControl(),
  10.           postalcode: new FormControl()
  11.           }),
  12.         });
  13.         onSubmit() {
  14.           console.log(this.userForm.value);
  15.         }
  16. }
  17. ===
  18. app.component.html
  19.  
  20. <form [FormGroup]="userForm" (ngSubmit)="onSubmit">
  21. <input FormControlName="name">
  22. <input FormControlName="email">
  23. <div FormGroupName="address">
  24.         <input FormControlName="city">
  25.         <input FormControlName="postalcode">
  26. </div>
  27. </form>