Angular 2 Date Input not binding to date value

后端 未结 10 1933
醉梦人生
醉梦人生 2021-01-30 16:16

trying to get a form set up but for some reason, the Date input in my html is not binding to the object\'s date value, despite using [(ngModel)]

html:

&l         


        
10条回答
  •  一整个雨季
    2021-01-30 16:49

    Instead of [(ngModel)] you can use:

    // view
    
    
    // controller
    parseDate(dateString: string): Date {
        if (dateString) {
            return new Date(dateString);
        }
        return null;
    }
    

    You can also choose not to use parseDate function. In this case the date will be saved as string format like "2016-10-06" instead of Date type (I haven't tried whether this has negative consequences when manipulating the data or saving to database for example).

提交回复
热议问题