-1

How can i use momentjs in ionic 4 view?

in calendar.page.html moment is unresolved

  <p>{{moment().getDay()}}</p>

Unresolved function or method moment()

in calendar.page.ts i can use moment

import * as moment from 'moment';
Janneck Lange
  • 882
  • 2
  • 11
  • 34

1 Answers1

1

Your current code is not working because right now your view is looking for a method moment in your controller. I see two solutions:

1) Add a function to your controller which interacts with MomentJS:

In your controller add:

getMomentDay() {
    return moment().getDay();
}

Next in your view change the line to this:

<p>{{ getMomentDay() }}</p>

2) Use an Angular plugin which exposes MomentJS the Angular way like ngx-moment.

Mathyn
  • 2,436
  • 2
  • 21
  • 33