2017-10-20 151 views
1

我需要将此日期传递给api,它需要是一个字符串。我如何做到这一点,因为我使用ng-bootstrap datepicker?当我做了date: this.date.toString()时,它返回[object] [Object]。我想这是一个字符串格式化日期到要传递到API的字符串

<div class="input-group col-md-3"> 
     <input class="form-control" placeholder="yyyy-mm-dd" name="dp" ngbDatepicker #d="ngbDatepicker" formControlName="date" required> 
     <button class="input-group-addon" (click)="d.toggle()" type="button"> 
      <i class="fa fa-calendar" aria-hidden="true"></i> 
     </button> 
</div> 

TS

this.date = this.myForm.get('date').value 

date: this.date.toString(), 
+0

实际上,您正在API中发送所有表单日期。或只有日期数据? –

+0

@Ajmalsha。那么这个日期来自于这个表格。我的问题是,我返回[对象] [对象] –

+0

所以你的要求是将表单数据转换为字符串。是吗? –

回答

1

我这样做。 this.date = this.parserFormatter.format(this.myForm.get('date').value) AND我将它导入import {NgbDateParserFormatter} from '@ng-bootstrap/ng-bootstrap';