Невозможно вызвать веб-API, потому что не получается получить дату в правильном формате для добавления в URL - PullRequest
0 голосов
/ 19 ноября 2018

Всякий раз, когда я пытаюсь вызвать веб-API, используя значение из datepicker, оно странным образом отображает дату, что приводит к неправильному запросу с сервера.

GET https://lihcode -lufthansa-open-new-v1.p.mashape.com / v1 / операций / расписаний / sfo / bom / 1542738600000? Limit = 10 400 (неверный запрос).

 Here date is 154273860000, but I want date in 2018-11-20(yyyy-mm-dd).

и вот мой компонент html для даты.

<input required matInput #input maxlength="3" 
name="destination" placeholder="Enter destination" 
class="form-control 
[(ngModel)]="flightSchedule.destination">
<mat-hint align="end">Destination airport.             
</mat-form-field>

и мой модальный класс:

export class FlightSchedule {

    constructor(
        public destination: string,
        public origin: string,
        public date: string,
        public limit: string
    ) {}

}

Мне нужна помощь, пожалуйста, кто-нибудь, помогите мне

Заранее спасибо

1 Ответ

0 голосов
/ 19 ноября 2018

1001 * Отредактировано * Попробуйте отформатировать дату для события ngModelChange, но вам нужно присвоить другое свойство (formatedDate) и получить дату из свойства formatedDate. <input required matInput #input maxlength="3" name="destination" placeholder="Enter destination" class="form-control [(ngModel)]="flightSchedule.destination" (ngModelChange)="formater(flightSchedule.date)"> <--- here Добавить новую недвижимость formatedDate export class FlightSchedule { constructor( public destination: string, public origin: string, public date: string, public formatedDate?: string, <--- here public limit: string ) {} } Добавить функцию в свой класс formater(unixTime: number) { var date = new Date(unixTime); var myDate = `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}T${date.getHours()}:${date.getMinutes()}`; this.flightSchedule.formatedDate = myDate; } Для моментов formater(unixTime: number) { const date = new Date(unixTime); const myDate = moment(date).format('YYYY-MM-DDTHH:mm); this.flightSchedule.formatedDate = myDate; }

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...