Показать LocaldateTime в угловом

Я использую DATETIME для хранения даты в MariaDB. Я также использую LocalDateTime для хранения в Java значения даты:

private LocalDateTime created_at;

В Angular я использую тип Date:

public created_at: Date

Сделка:

export class Transaction {
  constructor(
    public id: string,
    public name: string,
    public status: string,
    public type: string,
    public created_at: Date
  ) {}
}

Обслуживание:

import {Injectable} from '@angular/core';
import {HttpClient, HttpParams} from "@angular/common/http";
import {TransactionFilter} from "../domain/transaction-filter";
import {Observable} from "rxjs/index";
import {environment} from "../../../environments/environment";
import {Transaction} from "../domain/transaction";
import {PagedResult} from "../common/paged-result";
import {HttpUtils} from "../common/http-utils";
import {DateUtil} from "../common/date-util";

@Injectable({
  providedIn: 'root'
})
export class TransactionService {

  constructor(private http: HttpClient) {
  }

  search(filter: TransactionFilter, page: number, size: number): Observable<PagedResult<Transaction>> {
    let params = this.buildFilterParams(filter);
    let pagedFilter = HttpUtils.appendPageParams(params, page, size);

    return this.http.get<PagedResult<Transaction>>(environment.api.urls.transactions.base, {params: pagedFilter});
  }

  private buildFilterParams(filter: TransactionFilter): HttpParams {
    let params = new HttpParams();

    if (filter.name) {
      params = params.append('name', filter.name);
    }
    if (filter.id) {
      params = params.append('id', filter.id);
    }

    if (filter.from) {
      params = params.append('from', DateUtil.offsetDate(filter.from.toISOString()));
    }

    if (filter.to) {
      params = params.append('to', DateUtil.offsetDate(filter.to.toISOString()));
    }
    return params;
  }

  save(transaction: Transaction) {
    return this.http.post(environment.api.urls.transactions.base, transaction);
  }

  persist(transaction: Transaction) {
    return this.http.post(environment.api.urls.transactions.persist(transaction.id), transaction);
  }

  get(transactionId: string): Observable<Transaction> {
    return this.http.get<Transaction>(environment.api.urls.transactions.get(transactionId));
  }

  export() {
    return this.http.get(environment.api.urls.transactions.export,  { responseType: 'blob' });
  }
}

Составная часть:

import {Component, OnInit} from '@angular/core';
import {of} from "rxjs/index";
import {flatMap} from "rxjs/internal/operators";
import {Transaction} from "../domain/transaction";
import {TransactionService} from "../service/transaction.service";
import {ActivatedRoute} from "@angular/router";

@Component({
  selector: 'app-transaction-details',
  templateUrl: './transaction-details.component.html',
  styleUrls: ['./transaction-details.component.scss']
})
export class TransactionDetailsComponent implements OnInit {

  transaction: Transaction;

  constructor(private transactionService: TransactionService,
              private route: ActivatedRoute) { }

  ngOnInit() {
    this.route.params.pipe(
      flatMap(params => {
        if(params['id']) {
          return this.transactionService.get(params['id']);
        } else {
          return of(null);
        }
      })
    ).subscribe(value => {
      if(value != null) {
        this.transaction = value;
      }
    });
  }

}

Но я получаю исключение ОШИБКА TypeError: Невозможно прочитать свойство 'create_at' из неопределенного.

Какой тип даты я должен использовать в Angular?

0 ответов

Другие вопросы по тегам