Base solution for your next web application
Open Closed

Angular build error #8217


User avatar
0
farhantufail created

Hi Dear, I'm having trouble in building my angular project version 7.3.0. The error is 'Property '_d' does not exist on type 'Moment'.' I'm binding date object in [(ngModel)]="model.date._d".


8 Answer(s)
  • User Avatar
    0
    aaron created
    Support Team

    Try .toDate() instead: [(ngModel)]="pssaleh.docDate.toDate()"

    From https://momentjs.com/guides/#/lib-concepts/internal-properties:

    As such, the values of _d and any other properties prefixed with _ should not be used for any purpose.

    To print out the value of a Moment, use .format(), .toString() or .toISOString().

    To retrieve a native Date object from Moment, use .toDate(). This function returns a properly shifted date for interaction with third party APIs.

  • User Avatar
    0
    farhantufail created

    Hi @aaron it is not working. I'm sharing code with you. please help me in this regard. actually on initialize I also want to show current date seleected.

    HTML : <input class="form-control m-input form-control-sm" [(ngModel)]="pssaleh.docDate.toDate()" type="datetime" bsDatepicker id="PSSALEH_DocDate" name="PSSALEH_DocDate">

    TS : ngOnInit() { this.pssaleh = new CreateOrEditPSSALEHDto(); this.pssaleh.docDate = moment(); }

    Class : export class CreateOrEditPSSALEHDto { docDate!: moment.Moment | undefined; }

    kindly help me in this regard. As We have alot of date fields in our application

  • User Avatar
    0
    aaron created
    Support Team

    What's the error now?

  • User Avatar
    0
    farhantufail created

    @aaron this is the error. it is saying that unexpected token "="

  • User Avatar
    0
    aaron created
    Support Team

    That seems unrelated. Can you show the full line?

  • User Avatar
    0
    farhantufail created

    Yes sure @aaron.This is the screenshot.

  • User Avatar
    0
    aaron created
    Support Team

    I was mistaken about [(ngModel)].

    ASP<span></span>.NET Zero v7.2.0+ implements datePickerMomentModifier directive. Try this:

    - [(ngModel)]="pssaleh.docDate.toDate()"
    + datePickerMomentModifier
    + [(date)]="pssaleh.docDate"
    
  • User Avatar
    0
    ismcagdas created
    Support Team

    This issue is closed because it has not had recent activity for a long time.