Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

moment is giving me error in angular 5 html template

I am using moment v2.22.0 in angular 5, and this is how I have imported it in module -

import * as moment from 'moment';

and using it in component as -

export class ChatComponent {
  .
  .
  .
  public moment: any = moment;
  .
  .
}

and when I am using it in html template -

<div>{{moment(activeTeam.createdAt).format('LL')}}</div>

it is giving me an error message that -

[Angular] Member 'moment' is not callable

can anyone tell me what I am doing wrong !!

like image 866
samar taj Shaikh Avatar asked Aug 27 '18 10:08

samar taj Shaikh


2 Answers

cli (run in console)

// install moment js
npm install moment --save

component declaration (ts)

// import and declare moment
import * as moment from 'moment';
moment: any = moment;

template file (html)

// template syntax
<p>{{moment(date_time_variable).format('ll')}}</p>
like image 157
Bhaskararao Gummidi Avatar answered Oct 04 '22 21:10

Bhaskararao Gummidi


Don't use any, declare without it

import * as moment from 'moment';
moment = moment;
like image 34
Suroor Ahmmad Avatar answered Oct 04 '22 22:10

Suroor Ahmmad