0

I'm trying to bind my data using formbuilder (formControlName)

Well it is working correctly when adding data but the datepicker is empty when reading or trying to update the data. This is my html code

 <div class="form-group">
            <label for="picker2" class="control-label">{{'DateOfExpense' | translate}}</label>
            <div class="input-group">
              <input class="form-control" [matDatepicker]="picker" readonly
                placeholder="{{'DateOfExpense' | translate}}"  
                formControlName="DateOfExpense" >
              <mat-datepicker-toggle matSuffix [for]="picker"  ></mat-datepicker-toggle>
              <mat-datepicker #picker></mat-datepicker>
              <mat-error *ngIf="submitted && f.DateOfExpense.errors!=null">
                  <div *ngFor="let error of getErrors(f.DateOfExpense)">
                      - {{ error | translate}}
                  </div>
              </mat-error>
            </div>
          </div>
zarzou
  • 113
  • 14

2 Answers2

0

Did you wrap the form elements(input etc) in form tag and gave it a formGroup? You might want to go through the docs once

Tony
  • 152
  • 2
  • 15
0

If you use formControlName in HTML temple then it should be under corresponding FormGroup instance of your angular component, only then value of input field will bind to the component data.

Hope below link Will help you to understand the usage of formControlName. https://stackoverflow.com/a/40172009/1430266

prabhakaran
  • 323
  • 1
  • 11