2

I am passing a date value from a selected angular gridrow to my modal popup. One of the field is a Date field.

In my typescript, I got the databinding object defined as

public request = {

"MeetingDate": Date
};

When I call the function to open the modal popup,

editModal(content, selectedRow) {

const mdt = new Date(selectedRow.meetingDate);
const mm = mdt.getmonth();
this.request.meetingDate = { 'year': mdt.getFullYear(),  'month': mm, 'day': mdt.getDate() };

this.modalService.open(content);
}

I am getting an error stating

Type '{ 'year': number; 'month': numberl 'day': number; }' is not assigna ble to to type DateConstructor

Object literal may only specify konw properties, and ''year'' does not exist in type 'DateConstructor'

I tried a few other methods like this.request.meetingDate = selectedMeetingDt but the value does not show up on the UI datepicker. I also tried meetingDate = new Date(...) but that is not working either.

Even though I declare the property to be Date, in the function, the cursor is show me that its a DateConstructor.

Any help is greatly appreciated.

Thanks.

1
  • const mm - mdt.getmonth(); is this line correct ? Commented Oct 29, 2018 at 18:15

1 Answer 1

1

Just in case anyone ever encounter this error on Angular Typescript,

Originally I databinded the datepicker with this object

public meetingRequest = { "MeetingDt": Date, "PublicDate": Date, };

I had to move the Date fields outside the object to get it to build. In my Save function,

I had to do something like this

meetingRequest.meetingDate = this.MeetingDate.ToDateString();

This got me pass the issue and its working, but it should have worked with the object which I am using to pass to the web api. Wierd!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.