How to make a nested JSON from a form in Angular 2 -


i trying make nested json, taking values form. have 2 interfaces

export interface user{ username:string; name:string; passwordfield:password; }  export interface password{ password:string; secretquestion:string; } 
<form #myform="ngform" (ngsubmit)="onsubmit(myform.value)">   <div class="form-group">   <label> <b>form title</b></label>   <hr>     <label for="user name">user name:</label>     <input type="text" required [(ngmodel)]="user.username" class="form-control" id="username" name="username">   </div> <label for="name"> name:</label>     <input type="text" required [(ngmodel)]="user.name" class="form-control" id="name" name="name">   </div>   <div class="form-group">     <label for="password">password:</label>     <input type="password" required [(ngmodel)]="user.passwordfield.password" class="form-control" id="password" name="password">   </div> <div class="form-group">     <label for="secret question">secret question:</label>     <input type="text" required [(ngmodel)]="user.passwordfield.secretquestion" class="form-control" id="secretquestion" name="secretquestion">   </div>   <button type="submit"[disabled]="!myform.valid" class="btn btn-default">submit</button> </form>  
onsubmit(user:user){  alert(json.stringify(user))  } 

but here in alert {}, passing values form as

<label for="name"> name:</label>     <input type="text" required [(ngmodel)]="name" class="form-control" id="name" name="name"> 

makes simple json. can convert form obj obj of class , not dirctely of type interface??


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -