Questions tagged [angular2-moment]

Angular2 moment provides pipes for using momentjs methods in the angular environment. Make sure to include momentjs and angular tags along with this tag. Use angular-moment tag for the angularjs version of the library.

angular2 moment is a plugin that adds the following pipes to Angular based on the moment.js library.

  • Pipes
    • amTimeAgo - Use to format relative time
    • amCalendar - Format a date using moment.js calendar() method
    • amDateFormat - Format a date using moment.js format() method
    • amParse - Parse a custom-formatted date into a moment object
    • amFromUnix - Convert a unix-timestamp into a moment object
    • amDuration - Format a duration in a human readable format
    • amDifference - Get the difference between two dates in milliseconds
    • amAdd - Add hours, minutes or seconds from the specified date.
    • amSubtract - Subtract hours, minutes or seconds from the specified date.
    • amUtc - Create or switch the current moment object into UTC mode

References

Related Tags

46 questions
24
votes
1 answer

How to add days to a date in Angular2?

I simply want to create a date that is 3 days from now for use in a typescript angular component. I have looked at Angular2 moment but this seems only to relate to pipes. Although I did see this article about using pipes in code, looks a bit…
Mark Chidlow
  • 1,432
  • 2
  • 24
  • 43
17
votes
8 answers

How to exclude moment locales from angular build?

In my angular 5 application, when I create build using ng build --prod --sm and open source map explorer, moment takes lot of space in the main.js file. I have found all the locales gets loaded when I use import * as moment from 'moment'; I have…
Shikha
  • 551
  • 5
  • 20
7
votes
3 answers

Angular 8 Moment - Error: Cannot call a namespace ('moment')

while building an angular 8 project using moment I face this error message : ng build @myproject/common Error: Cannot call a namespace ('moment') I found similar issues over internet and suggested solutions described as below for Angular 6/7. But…
Emmanuel BRUNET
  • 1,286
  • 3
  • 19
  • 46
5
votes
5 answers

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…
samar taj Shaikh
  • 1,165
  • 11
  • 18
5
votes
4 answers

Template parse: The pipe could not be found

I am getting the error: Template parse errors: The pipe 'amDateFormat' could not be found Here is my app.module.ts import { NgModule } from '@angular/core'; ... import { MomentModule } from 'angular2-moment'; ... @NgModule({ declarations: [ …
coler-j
  • 1,791
  • 1
  • 27
  • 57
3
votes
2 answers

How to Subtract firebase timestamp with current time and check if it exceeds 5 minutes in Angular

I have a angular app in which i am storing records to firebase with the timestamp using firebase.database.ServerValue.TIMESTAMP Now i want to check if the timestamp added to the database exceeds five minutes. I tried using moment in my Component but…
Rahul
  • 427
  • 3
  • 7
  • 16
2
votes
2 answers

ERROR in /node_modules/moment-timezone/index.d.ts (47,77): ';' expected. how to fix

I'm working in an Angular 4 application and everything worked fine until I clone my repo and runned npm install and ng serve This error seems to be the problem ERROR in C:/Users/mypcuser/Desktop/myproject/node_modules/moment-timezone/index.d.ts…
Sergio Mendez
  • 1,311
  • 8
  • 33
  • 56
2
votes
2 answers

isBefore function in momentjs is not working

I try to check if a certain time in h:mm is before another time with same format. However, the console shows me either an error saying isBefore is not a function or it always print false. I use this code in Ionic 3/Angular. If I code as follows, the…
Lorenzo Varano
  • 411
  • 4
  • 22
2
votes
1 answer

Moment js interval for a day in 12 hours format

In 12 hours format,i have to create a interval of 15 minutes in moment which is working fine with 30 minutes interval. var hours = []; for (let hour = 0; hour < 24; hour++) { hours.push(moment({ hour }).format('h:mm a')); …
Mohamed Sahir
  • 2,482
  • 8
  • 40
  • 71
2
votes
1 answer

Angular 5 material datepicker not working with moment date adapter and target es2015

After switching from target es5 to es2015 (es6), the datepicker is not working anymore when deploying with --prod flag. I also tried adding --aot flag, but it didn't change anything. The outcome looks as follows: Following Error is thrown: Using…
2
votes
1 answer

Moment converting digit into date

Trying to understand how moment.js is converting a string to date, I've bounced into this issue. let date = "User has logged in to more than 10 ."; console.log(moment(date)); //output date let invalid = "User has logged in to more than 10…
eyalewin
  • 360
  • 4
  • 20
2
votes
1 answer

How to display time format using angular2-moment

.html {{2018-02-26T12:00:14.151Z | amParse : 'YYYY/MM/DD' | amDateFormat : 'LL'}} The above above gives the result as February 26, 2018 but I need the result as FEBRUARY 2018 . I am using anular2-moment module link here I have to use this module…
Aditya
  • 2,358
  • 6
  • 35
  • 61
2
votes
1 answer

Dynamic locale on angular2/moment and ngx-translate

Angular 4.x - ngx-translate - angular2-moment How to use "amTimeAgo" and "amLocale" with dynamic locale? I mean, i.e this works

{{ note.createdAt | amLocale: 'es' | amTimeAgo }}

but I want to convert 'es' into a dynamic variable.…
2
votes
1 answer

I'm getting errors trying to install angular2 moment

The instructions here didn't work for me: https://github.com/urish/angular2-moment I did npm install --save angular2-moment worked fine, then I attempted to do: typings install --save moment but got typings: command not found error, then I did…
Spilot
  • 1,495
  • 8
  • 29
  • 55
2
votes
0 answers

moment has no exported member 'MomentLanguage'

I'm using moment v 2.15.2 with angular2 and I have this code import { MomentLanguage } from 'moment'; import * as moment from 'moment'; moment.updateLocale('ar', { preparse: (str) => { return str.replace(/\u200f/g,…
Ibraheem Al-Saady
  • 854
  • 3
  • 14
  • 30
1
2 3 4