Angular 2 Date Input not binding to date value

后端 未结 10 1929
醉梦人生
醉梦人生 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:42

    use DatePipe

    > // ts file
    
    import { DatePipe } from '@angular/common';
    
    @Component({
    ....
    providers:[DatePipe]
    })
    
    export class FormComponent {
    
    constructor(private datePipe : DatePipe){}
    
        demoUser = new User(0, '', '', '', '', this.datePipe.transform(new Date(), 'yyyy-MM-dd'), '', 0, [], []);  
    }
    

提交回复
热议问题