将字符串格式化为要传递给API的字符串

时间:2017-10-20 03:49:50

标签: angular angular-http ng-bootstrap angular-forms

我需要将此日期传递给api,它需要是一个字符串。我怎么能这样做,因为我正在使用ng-bootstrap datepicker?当我做date: this.date.toString()时,它返回[object] [Object]。我希望它是一个字符串

<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(),

1 个答案:

答案 0 :(得分:0)

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

中导入了它