Issue with rendering date in <ion-datetime> element

In the process of developing my ionic app (v-4), I encountered an issue with displaying the date from the api. The structure of my JSON data is as follows:

{
user_name: "Jhon"
status: "Open"
meeting_date: "31-08-2019"
remark: "No remarks"
request_id: 958
}

I attempted to showcase the date using <ion-datetime> in the following manner:

HTML

  <form [formGroup]="editForm">
     <ion-item>
            <ion-label position="stacked">Date</ion-label>
            <ion-datetime formControlName="meeting_date" [(ngModel)]="resObj.meetingDate"></ion-datetime>
      </ion-item>
 </form>

TS

public resObj;
ngOnInit() {
    this.resObj = this.navParams.data.paramRequest;
    this.updateForm = this.fb.group({
      remark : [null],
      .
      .
      meeting_date: [null],
    });
  }

An error occurred stating: Error parsing date: "undefined". Please provide a valid ISO 8601 datetime format: https://www.w3.org/TR/NOTE-datetime

I attempted a solution by referencing ionic 2 ion-datetime ISO Format issue

This involved using the ISO format before displaying the date in the template like so:

HTML

  <form [formGroup]="editForm">
     <ion-item>
            <ion-label position="stacked">Date</ion-label>
            <ion-datetime formControlName="meeting_date" [(ngModel)]="meetingDate "></ion-datetime>
      </ion-item>
 </form>

TS

public resObj;
ngOnInit() {
    this.resObj = this.navParams.data.paramRequest;
    const meetingDate =  this.resObj.meeting_date.toISOString(); <======
    this.updateForm = this.fb.group({
      remark : [null],
      .
      .
      meeting_date: [null],
    });
  }

Despite these efforts, the date still does not display properly in ion-datetime

I'm having trouble pinpointing what may have caused this issue.

Answer №1

My recommendation is to utilize moment library and you can even create a custom pipe as explained here. You can implement it like this:

<span >{{ resObj.meetingDate | momentPipe: 'dddd D MMM YYYY' }}</span> 

Additional date formats can be found here.

UPDATE: create a form

public someForm: FormGroup;
  ngOnInit() {
    this.initSomeForm();
  }
  initSomeForm() {
    this.someForm = new FormGroup({
      userName: new FormControl(this.resObj.user_name, [Validators.required]),
      meetingDate: new FormControl(this.resObj.meeting_date, [Validators.required]),
      status: new FormControl(this.resObj.status, [Validators.required]),
      remark: new FormControl(this.resObj.remark),
      requestId: new FormControl(this.resObj.request_id),
    });
  }

In the HTML

  <form [formGroup]="someForm">
<ion-item>
       <ion-label position="stacked">Date</ion-label>
       <ion-datetime formControlName="meetingDate" displayFormat="MM DD YY"></ion-datetime>
 </ion-item>

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

CSS class 'nav nav-pills nav-justified' does not stack tabs properly on mobile devices

Currently, I am utilizing the most recent version of Bootstrap within an Angular environment. However, I have encountered an issue where the class "nav nav-pills nav-justified" does not stack the tabs properly when the screen size is reduced below 768px. ...

The real file that was brought in after indicating a module in the node_modules directory that was coded in Typescript

After creating a typescript module named moduleA, I am ready to publish this package and make it accessible from another typescript project. Currently, for testing purposes, I have installed 'moduleA' using 'npm install ../moduleA'. Th ...

Adding css-element-queries to an angular 6 project

I am currently attempting to install and utilize the css-element-queries library. To install, I executed the following command: npm i css-element-queries Following that, I attempted to import the ResizeSensor class from the library in this manner: impo ...

Exploring Angular 5: Managing HTTP Headers and Utilizing URL Parameters

I am currently working on an Angular project that involves third-party authentication, which redirects to our app with additional information in the HTTP headers. Here are the questions I have: What is the best way to extract the information from the HT ...

A helpful guide on passing props to ReactJS components when redirecting

I am facing an issue with passing props while redirecting to a route using React Route (Redirect to). The component (SideBar) is not receiving any props. Can you guide me on how to send and receive props in the component? My requirement is to send a prop f ...

Is there a way to pass a token variable from the main page to an iframe without relying on a post message?

I am seeking assistance on how to transfer a variable from a parent window to an iframe. My situation is as follows: I am working with 2 Angular5 applications named A and B . Application B is loaded within Application A using an iframe. The aut ...

Creating a velocity gauge style graph in Angular 4: A step-by-step guide

Hello, I'm currently working on building a speedtest-inspired application. While everything else is going smoothly, I'm struggling to incorporate a speedometer-like chart in Angular 2/4. Despite searching extensively, I've only come across J ...

Tips for resolving the issue when encountering an unknown error message at useSelector: Unhandled Promise Rejection: TypeError: useSyncExternalStore is not defined

Encountered the following error : Unhandled Promise Rejection: TypeError: useSyncExternalStore is not a function. (In 'useSyncExternalStore(subscribe, getSelection, getServerSelection)', 'useSyncExternalStore' is undefined) https://i.s ...

Is there a way to make sure that ngbpopovers stay open even when hovering over the popover content?

I have implemented a ngbpopover to display user information on an element. Currently, the popover is triggered on both hover and click events, but I would like it to remain open when hovered over, instead of closing as soon as the mouse moves away. How c ...

Pinia is having trouble importing the named export 'computed' from a non-ECMAScript module. Only the default export is accessible in this case

Having trouble using Pinia in Nuxt 2.15.8 and Vue 2.7.10 with Typescript. I've tried numerous methods and installed various dependencies, but nothing seems to work. After exhausting all options, I even had to restart my main folders on GitHub. The dep ...

Creating a test scenario for post and get functionalities in an Angular 8 service to evaluate its karma

I'm struggling with writing a test case for the POST method in Karma since I am new to it. Below is my service.ts file: constructor(private httpclient: HttpClient) { } url = 'http://localhost:8047/some_url'; check: Check[]; public newBe ...

What is the best way to pass a conditional true or false value to React boolean props using TypeScript?

I am currently utilizing the Material UI library in combination with React and Typescript. Whenever I attempt to pass a conditional boolean as the "button" prop of the component, I encounter a typescript error stating: Type 'boolean' is not assi ...

Even with proper validation, a Typescript object can still potentially be null

In my current project, I am utilizing TypeScript and attempting to compare a value within an object to another value. However, I am encountering an issue with TypeScript's "Object possibly null" error: https://i.sstatic.net/5Wd76.png Despite attempt ...

Transferring information from RSC to a nested child component using the Next.js application router

Currently, I am in the process of migrating a large Pages router next.js project to the App directory. However, I have encountered a common challenge for which I am struggling to find a suitable solution. Despite being accustomed to the convenience of Reac ...

Abstraction of the leaflet directive within a personalized directive

Currently, I am developing an Angular 6 application that utilizes ngx-leaflet for leaflet functionalities. Our goal is to design a base component that can be customized by incorporating directives. We are aiming for a more abstract approach compared to the ...

What is the best way to incorporate a string value from an external file into a variable in TypeScript without compromising the integrity of special characters?

I am encountering an issue with importing a variable from a separate file .ts that contains special characters, such as accents used in languages like French and Spanish. The problem I am facing is that when I require the file, the special characters are ...

The system encountered an issue: Unable to access the filter property of an undefined property

Here is my form code in TypeScript: this.editForm = this.fb.group({ 'dropoffs': this.fb.array(this.createDropOffFacility(data.dropoffs.filter(picks => picks.drop_facility !== ''))), }); createDropOffFacility(facilities) { ...

Incorporate a linked select dropdown into the registration form

I am working on a sign-up form and trying to integrate 2 linked select boxes into the form. The code for the linked select boxes works fine separately but when I attempt to add it to the form, it doesn't display as expected. I attempted to incorporate ...

Encountering difficulties in transmitting ngModel across multiple layers

I'm encountering a problem when trying to pass ngModel through the second child component. It seems that as soon as I do that, it stops working. In order to pass the ngModel, I implemented this abstract class: export abstract class AbstractValueAcces ...

Using a local variable within quotes in Angular 4 (HTML) and utilizing ngFor

In my current project, I am utilizing Angular2-Collapsible. The objective is to display the details upon clicking a table row. Below is the code snippet provided. Specifically, if I add [detail]= "detail1", the collapsible-table-row-detail will appear when ...