0

I'm utilizing the ng2-bootstrap datePicker, and whether I leave the initial value undefined, or if I use the initDate, I get an unexpected behavior. Right away upon loading the page the variable bound to ngModel of the directive, in my case:

[(ngModel)]="campaign.startDate"

campaign.startDate logs as:
FIRST - today, or an assigned value if I set it arbitrarily in the ngOnInit
THEN - takes on the value I have assigned it once my request comes back with a new value
THEN - today

I have no idea what triggers that third step, and as far as I can tell it's not coming from my code, but due to the 2 way binding, the datePicker itself for some reason is assigning it a value of "today"

TS

getCampaign(id:number){
    this._campaignService.getCampaignById(id)
        .subscribe(
            campaign => {
                this.campaign = campaign;
            }
        )
}
ngOnInit(){
    this.campaign = {
        startDate:new Date()
    }
    this.getCampaign(4);
}

and HTML

<datepicker [(ngModel)]="campaign.startDate" [showWeeks]="true"></datepicker>
Pardeep Jain
  • 84,110
  • 37
  • 165
  • 215
petaltank
  • 1
  • 1
  • 2

0 Answers0