Angular 2: How to use JavaScript Date Object with NgModel two way binding

后端 未结 7 1716
醉酒成梦
醉酒成梦 2020-12-02 10:01

I\'m working with Angular 2 and I have this code:

JS, this code initiates the employee-variable for the template:

handleEmployee(employee : Employee)         


        
7条回答
  •  眼角桃花
    2020-12-02 10:27

    Created a local string variable

    dateField: string;
    

    And I'm binding that to my form

    Date input

    
    

    Later just assign that back to the Date property just before making any API call

    insert() {
        this.myObjet.date = new Date(this.dateField);
        ... call api
    
    update() {
        this.myObjet.date = new Date(this.dateField);
        ... call api
    

提交回复
热议问题