Base solution for your next web application
Open Closed

Moment Error in Angular Project #8047


User avatar
0
farhantufail created

Dear I'm gettting this error for unknow reason.Please help me in this regard. identifier '_d' is not defined.'Moment' does not contain such a member Angular. ____

we are using product version of 7.2.3. Thanks


7 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    Please share the code for the corresponding component.

  • User Avatar
    0
    farhantufail created
    ngOnInit(): void {
            const saleInvoiceId = this.route.snapshot.params.id;
            if (!saleInvoiceId) {
                this.getCreate();
            } else {
                this._saleInvoicesServiceProxy.getSaleInvoiceForEdit(saleInvoiceId).subscribe(result => {
                    this.saleInvoice = result.saleInvoice;
                    if (this.saleInvoice.dueDate) {
                        this.dueDate = this.saleInvoice.dueDate.toDate();
                    }
                    if (this.saleInvoice.approvedDate) {
                        this.approvedDate = this.saleInvoice.approvedDate.toDate();
                    }
                });
            }
        }
        
        this is the code . and one thing more is I'm getting this error only when I open form for edit.
        Please reply @maliming
    
  • User Avatar
    0
    musa.demir created

    hi @farhantufail Can you please change your ngOnInit function and share console log results.

    ngOnInit(): void {            
            const saleInvoiceId = this.route.snapshot.params.id;
            console.log("saleInvoiceId: ",saleInvoiceId);//log that
            if (!saleInvoiceId) {
                this.getCreate();
            } else {
                this._saleInvoicesServiceProxy.getSaleInvoiceForEdit(saleInvoiceId).subscribe(result => {
                    console.log("result.saleInvoice: ",result.saleInvoice);//log that
                    this.saleInvoice = result.saleInvoice;
                    if (this.saleInvoice.dueDate) {
                        this.dueDate = this.saleInvoice.dueDate.toDate();
                    }
                    if (this.saleInvoice.approvedDate) {
                        this.approvedDate = this.saleInvoice.approvedDate.toDate();
                    }
                });
            }
            
            console.log((new moment())._d);//log that
        }
    
  • User Avatar
    0
    farhantufail created

    Yes Sure Brother. I'm sharing two screenshots with you.

  • User Avatar
    0
    musa.demir created

    Sory I just tried console.log((new moment())._d);//log that on chrome console that's why it gave you an error on angular. You can change it with:

    let date = moment();
    console.log("moment", date);
    
    let _d = (date as any)._d;
    console.log("_d", _d)
    
  • User Avatar
    1
    musa.demir created

    By the way, is getSaleInvoiceForEdit success ?

    It looks like your page initializing before you get value from server. That's why saleInvoice is null because it is not yet set. You can add parameter like loading, set it true by the default. After you set saleInvoice set loading false. And use *ngif on your container div. That might solve your problem.

  • User Avatar
    0
    farhantufail created

    Thank you page was initializing before server response.

    Thanks alot