ng2-boostrap datePicker seems to overwrite ngModel

血红的双手。 提交于 2019-12-13 07:14:15

问题


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>

来源:https://stackoverflow.com/questions/35786890/ng2-boostrap-datepicker-seems-to-overwrite-ngmodel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!