Encountering a problem with an InvalidPipeArgument in Angular 6

Here's a quick summary of the situation:

  1. I recently upgraded my application to the latest version of Angular, moving from 5 to 6.
  2. All deployments in the packages.json file were updated using the ng update command.

In my application, I save a Date() value in the Cloud Firestore database under the field birthday_date (timestamp), utilizing an input with the DatePicker component from Angular Material.

  1. Prior to updating the dependencies, the birthday_date (timestamp) field returned a value of type Date (), allowing me to use {{ data.birthday_date | date }}.

  2. After updating the dependencies in package.json, the return is now a value of type Timestamp in the birthday_date (timestamp) field.

  3. To retrieve a Date () object now, I need to call the toDate () method.

    {{ data.birthday_date.toDate() | date }}

The earlier return was a Date () object:

Sat May 19 2018 20:35:12 GMT-0300

Post-update, the return is a Timestamp object:

Timestamp {seconds: 1527476400, nanoseconds: 0}

Updates in package.json involved:

"firebase": "4.11.0", ->
"firebase": "5.0.3"


"angularfire2": "5.0.0-rc.6", ->
"angularfire2": "5.0.0-rc.9",

Below depicts snippets of code from my application:

mycomponent.component.html:

<form name="myForm" [formGroup]="myForm" class="w-100-p">
<mat-form-field fxFlex="30">
    <input matInput [matDatepicker]="picker" formControlName="birthday_date " placeholder="Date of birth">
   <mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
   <mat-datepicker #picker startView="multi-year" disabled="false" touchUi="true"></mat-datepicker>
</mat-form-field>
</form>

The date does not display in the input due to returning a Timestamp, while the DatePicker component requires a Date () value.

list.component.ts:

<ng-container cdkColumnDef="birthday_date">
        <mat-header-cell *cdkHeaderCellDef mat-sort-header fxHide fxShow.gt-xs>Date of birth</mat-header-cell>
        <mat-cell *cdkCellDef="let data" fxHide fxShow.gt-xs>
           <p class="text-truncate">{{ data.birthday_date | date }}</p>
        </mat-cell>
</ng-container>

If I do not invoke the toDate () method like

{{ data.birthday_date.toDate() | date }}
, the following error surfaces:

ListComponent.html:81 ERROR Error: InvalidPipeArgument: 'Unable to convert "Timestamp(seconds=1526698800, nanoseconds=0)" into a date' for pipe 'DatePipe'
    at invalidPipeArgumentError (common.js:4238)
    at DatePipe.push../node_modules/@angular/common/fesm5/common.js.DatePipe.transform (common.js:5151)
    at checkAndUpdatePureExpressionInline (core.js:10801)
    at checkAndUpdateNodeInline (core.js:11375)
    at checkAndUpdateNode (core.js:11333)
    at debugCheckAndUpdateNode (core.js:11970)
    at debugCheckRenderNodeFn (core.js:11956)
    at Object.eval [as updateRenderer] (ListComponent.html:81)
    at Object.debugUpdateRenderer [as updateRenderer] (core.js:11948)
    at checkAndUpdateView (core.js:11320)

The Solution I Seek:

I am searching for a way to revert back to returning a Date() object instead of a Timestamp, as this modification has affected multiple parts of my application and is causing delays in my project.

Answer №1

I encountered a similar issue and managed to resolve it by using the following solution:

data.birthday_date.seconds * 1000 | date

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The confirmPasswordReset function in Angularfire auth is not defined in the User type

I am currently working on integrating password reset functionality using the angularfire2/auth class, following the steps outlined in this guide: https://medium.com/@c_innovative/implementing-password-reset-can-be-a-tricky-but-inevitable-task-737badfb7bab ...

TypeScript equivalent to Python's method for removing non-whitespace characters is achieved by

I understand that I can utilize .trim() to eliminate trailing spaces Is there a method to trim non-space characters instead? In [1]: str = 'abc/def/ghi/' In [2]: s.strip('/') Out[2]: 'abc/def/ghi' I am referring to the funct ...

Can callback argument types be contingent on certain conditions? For example, could argument 0 be null if argument 1 is a string?

I am attempting to implement conditional type logic for the parameter types of a callback function. In this scenario, the first argument represents the value while the second argument could be an error message. type CallbackWithoutError = (value: string, ...

Ensure that the injected service's constructor has completed before running tests in Karma 4 with Angular 7

I'm including a service in this manner: it('test name', inject([ Service], (hcs: Service) => { const pipe = new MyPipe(hcs); const expectedResult = ... //The constructor of the hcs-service must be completed before executing t ...

The type 'myInterface' cannot be assigned to the type 'NgIterable<any> | null | undefined' in Angular

I am facing an issue that is causing confusion for me. I have a JSON data and I created an interface for it, but when I try to iterate through it, I encounter an error in my HTML. The structure of the JSON file seems quite complex to me. Thank you for yo ...

Importing TypeScript Modules from a Custom Path without Using Relative Paths

If we consider the following directory structure: - functions - functionOne - tsconfig.json - index.ts - package.json - node_modules - layers - layerOne - tsonfig.json - index.ts - index.js (compiled index.ts ...

Obtain a string of characters from different words

I have been trying to come up with a unique code based on the input provided. Input = "ABC DEF GHI" The generated code would look like, "ADG" (first letter of each word) and if that is taken, then "ABDG" (first two letters o ...

Executing the Onclick event within a primeNG menu bar

Need help with triggering the On-click event in PrimeNG? If you're looking to navigate to the UserFormComponent.html page and add a new user when clicking on the 'New' menu bar using PrimeNG, here's how you can achieve it: You can fin ...

What causes React JS to continuously render in an infinite loop when using hooks and useState

I am struggling with updating the current state of my component based on a result using a custom hook in React. Whenever I try to update it, I end up in an infinite loop rendering due to my usage of the useState() hook. I am still new to working with Rea ...

What is the best way to incorporate a class creation pattern in Typescript that allows one class to dynamically extend any other class based on certain conditions?

As I develop a package, the main base class acts as a proxy for other classes with members. This base class simply accepts a parameter in its constructor and serves as a funnel for passing on one class at a time when accessed by the user. The user can spe ...

What is causing the "unable to resolve dependency tree" error when using ng new newApp?

Struggling with creating a new Angular app using the command ng new app-name? When running the command, you may encounter the following error in the command line. Installing packages (npm)...npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve depen ...

To ensure the specificity selector for material UI in React, it is essential to include an empty CSS definition

The styling for the unselected toggle button is working smoothly. However, when you don't define an empty class selector, the style of the selected toggle button does not show: ./App.js import * as React from "react"; { render ...

Following a successful compilation, the Angular application displays an empty page

Alert: Uncaught TypeError: Cannot read property 'length' of undefined at Object./src/components/Carousel.vue (Carousel.vue:123) at __webpack_require__ (bootstrap:1024) at Module../src/main.js (main.js:1) at __webpack_require__ (b ...

Struggling to troubleshoot issues with asynchronous tasks in Angular? Encountering timeouts while waiting for elements on an Angular page? Learn

Edit: I have identified the source of my issue with guidance from @ernst-zwingli. If you are facing a similar error, one of his suggested solutions might be beneficial to you. My problem stems from a known Protractor issue itself. For those who suspect the ...

Using Angular's ElementRef to set focus on an ion-textarea: "The 'setFocus' property is not found on the 'ElementRef' type."

After developing a textarea component that automatically focuses itself when created using the ngAfterViewInit() method, everything seemed to be working perfectly as expected. ngAfterViewInit() { if(this.text.length===0){ this.theinput.setFocus(); ...

Is there a code that ensures the date provided is not after the current date?

Is there a specific code that ensures the date entered is not in the future compared to the current date? <?php else if($cust_dob date("d-m-y")){ echo "Error : Your date of birth cannot be in future."; } ?> ...

Ensure that the value of a variable in the Ionic/Angular template has been properly initialized

I am currently facing an issue: I have an array of blog posts. Some of them have photos, while others do not. I aim to display the first photo if any are set. How can I verify whether the URL value in my array is set? <ion-header> <ion-navbar& ...

How to properly integrate Bootstrap with Angular 2?

Currently developing an angular2 app and contemplating whether to include bootstrap reference on the component level or in the index.html file. Interested to learn about the advantages and disadvantages of each approach. Thank you! ...

Tips for connecting data to an HTML page with Angular 2

My code is throwing an error message while I'm debugging: Error: Uncaught (in promise): TypeError: Unable to get property 'standard' of undefined or null reference Here is the relevant part of my code: student.component.ts: this._studentSe ...

Can a form be submitted using ViewChild in Angular5?

Can a form be submitted using ViewChild in Angular5? If so, how can it be achieved? I attempted to do this but was unsuccessful My Attempt: <form #form="ngForm" (submit)="submitForm(form)" novalidate> <input required type="text" #codeReques ...