javascript - How can I use an Angular Material Datepicker with a reactive / model-driven form? -


i have reactive (model-driven) angular form multiple form groups (formgroupname) , controls. form-fields on form controlled , populated formbuilder in associate typescript file.

i have text field on form i'm using collect date user. wanted associate angular material datepicker on field add "formcontrolname" attribute input field, error:

error: more 1 custom value accessor matches form control path: ' -> '

i can't use ngmodel (switch template driven form) else on form model-driven , control sits within formgroupname block. did try putting ngmodel on here see happen , angular complained can't mix ngmodel in here.

how can data-bind field (set initial value field on typescript side) , changes made user on template/view when form submitted while using angular material's datepicker? if angular material's date picker doesn't support model-driven forms, i'm willing use date-picker supports feature.

my model looks (the field that's relevant discussion step1.visitdate):

this.form = this.fb.group({         step1: this.fb.group({             representative: [null],             visitdate: [new date()],             category: ["retail store visit"],             contacttype: ["store visit"],             gopakstore: [null],             gopaklocation: [null],             eventtype: ["outreach"],             eventdescription: [null],             serviceplaza: [null],             inventorylocation: [null]         }),         step2: this.fb.group({             inventoryitemlocation: [null],             quantityavailable: [null],             quantitydistributed: [null],         })     }); 

my html template looks (the relevant parts):

<form [formgroup]="form" (ngsubmit)="onsubmit(form.value)" novalidate> <md-card class="users-listing" formgroupname="step1">     <md-card-content>         <div>             <md-input-container style="width:98%;">                 <input mdinput placeholder="visit date" [mddatepicker]="visitdatepicker" formcontrolname="visitdate" required trim maxlength="10">                 <button mdsuffix [mddatepickertoggle]="visitdatepicker"></button>             </md-input-container>             <md-datepicker #visitdatepicker></md-datepicker>         </div>     </md-card-content> </md-card> 


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -