Tuesday, July 25, 2017

How to make a hidden input type field in the Angular 2 paradigm.

DO: Put the hidden value, in this case theId, in the FormGroup!

this.v = new FormGroup({
   'myControl': new FormControl(''),
   'somethingElse': new FormControl(''),
   'theId': new FormControl('')
});
this.v.patchValue({
   'myControl': this.foo.bar,
   'somethingElse': this.foo.baz,
   'theId': this.foo.qux
});

 
 

DO NOT: Literally make an HTML control for the hidden value. In this case there is no control for theId.

<form [fromGroup]="v">
   <input type="text" formControlName="myControl">
   <br />
   <input type="text" formControlName="somethingElse">
   <br />
   <button (click)="makeMagic(v)">Go</button>
</form>

No comments:

Post a Comment