Error Datepipe Angular 6

Asked

Viewed 1,690 times

1

I just upgraded my Angular 5 application to Angular 6.

When saving a record in the Firebase database using mat-datepicker checking in the database I noticed that is correctly saving the date with type timestamp.

birth date: (12 July 2018 00:00:00 UTC-3).

When listing the records I can’t use the Angular Pipedate because there is an error, because it is returning from the database (Timestamp(Conds=1531.. in the data_birth column on mat-table;

Before I made this update to Angular 6, I was simply saving the object Date() that the mat-datepicker created and in the mat-table could do {{ date | date }} normally.

In my app.modulets.: I’m defining the LOCALE_ID;

import { registerLocaleData } from '@angular/common';
import localePt from '@angular/common/locales/pt';
registerLocaleData(localePt);

providers: [
    { provide: LOCALE_ID, useValue: 'pt-BR' },
]

I have tried to remove LOCALE_ID leaving the pattern, but it is still not working properly, when returning the object Date() that the mat-date-Picker creates in the bank, the date in the input or in the mat-table;

I don’t know if this is some change from Firebase or Angular, I don’t know what to do because I’m not getting to show the birth date in the mat-table nor in the form.

2 answers

0

In his app.module.ts, add that:

...

import { LOCALE_ID } from '@angular/core';
import { registerLocaleData } from '@angular/common';
import localePt from '@angular/common/locales/pt';
registerLocaleData(localePt);

...

@NgModule({
  ...

  providers: [
    { provide: LOCALE_ID, useValue: "pt-BR" }
  ]
})

0

Have you ever tried to convert in Angular the received date by passing inside a new Date()? I’ve done it several times and it worked.

Another thing too, I directly import the core to use Locale:

import { LOCALE_ID } from "@angular/core";

Try some of these options. It worked for me!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.