ng2-ui / datetime-picker

Angular2 DateTime Picker
https://ng2-ui.github.io/#/datetime-picker
MIT License
121 stars 62 forks source link

datetime-picker directive requires ngModel error #10

Closed Redigast13 closed 8 years ago

Redigast13 commented 8 years ago

Here is my code: <input type="text" class="form-control" placeholder="{{'FIELD_DATE' | translate}}" [formControl]="date" [ngModel]="dateValue" datetime-picker [date-format]="dateFormat"> I fetch dateValue from server and in first time this variable is empty. I have the error in console: datetime-picker directive requires ngModel

allenhwkim commented 8 years ago

This happens because of the following. Although you see the error, there must be no difference in functionality To silent the error, please assign an initialize your dateValue with an empty string.

    let dateNgModel: Date | String =  this.ngModel;
    if (!(this.ngModel instanceof Date || typeof this.ngModel === 'string')) {
      console.error("datetime-picker directive requires ngModel");
      this.ngModel = this.dateTime.formatDate(new Date(), this.dateOnly);
    }
Redigast13 commented 8 years ago

thank you!

0cv commented 8 years ago

I would nonetheless reopen the issue, because I would expect the plugin to support formControl / formControlName without needing ngModel. This "hacks" is indeed working, but that's not a proper solution I would say.