1

I'm trying to use PrimeNG datepicker inside a ngForm and apply required validation.

<p-calendar formControlName="eventStartDate"  
            inputStyleClass="form-control" 
            #eventStartDate="ngModel"  
            ngControl="eventStartDate"   
            id="eventStartDate" 
            [(ngModel)]="event.eventStartDate" 
            minDate="+1d"  
            [showIcon]="true"  
            required>
            </p-calendar>  
<span [hidden]="eventStartDate.valid || eventStartDate.pristine" 
      class="help-block">
      Start Date  is required !
</span> 

However, I'm getting an exception ,

Template parse errors:
There is no directive with "exportAs" set to "ngModel" ("                    
    <div class="input-group form-inline">
    <p-calendar [ERROR ->]#eventStartDate="ngModel"  
                name="eventStartDate" 
                formControlName="eventStartDate"  
                inputStyleClass="f").    

How should we add PrimeNG controls to angular form ?

Antikhippe
  • 6,316
  • 2
  • 28
  • 43
Jayantha Lal Sirisena
  • 21,216
  • 11
  • 71
  • 92

1 Answers1

0

I think you are using template driven forms.

Just remove formControlName="eventStartDate" and replace it with name="eventStartDate"and I believe this should work for you.

A J Qarshi
  • 2,772
  • 6
  • 37
  • 53