2017-10-20 178 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';