0

I have installed angular2-moment into angular2-cli. While installing, angular2-cli does not have system.js, so where can I put these settings into?

https://github.com/urish/angular2-moment/#for-systemjs-users

Also I'm also getting following error:

pipe missing

Basit
  • 16,316
  • 31
  • 93
  • 154
  • 1
    What is your exact *Angular 2* version? I have tried using `"angular2-moment": "1.0.0-beta.1"` with a `"angular-cli": "1.0.0-beta.15"` generated project based on *Angular 2.0.0*. Everything seems to be working OK. – Yuri Sep 30 '16 at 16:02
  • `angular 2.0.0` and `angular-cli: 1.0.0-beta.15` and `angular2-moment ^1.0.0-beta.1` – Basit Sep 30 '16 at 17:00
  • OK, so you match my test landscape. – Yuri Sep 30 '16 at 17:04
  • did you add configuration to system.js? because I'm not sure where to put that. – Basit Sep 30 '16 at 17:05
  • 1
    No, the Readme clearly states: **For System.js users**. *Angular-cli* doesn't use `system.js`, so don't bother with it. – Yuri Sep 30 '16 at 17:14

2 Answers2

4

Add the moment to your package.json under dependencies: "angular2-moment": "^1.0.0-beta.1". Then install it via: npm install --save.

Since you most probably use TypeScript, install Types for the moment lib: npm install @types/moment --save.

Then you need to import the MomentModule in your desired module. Eg.: import { MomentModule } from 'angular2-moment';.

And thats it, now you can use the moment pipes.

Yuri
  • 4,254
  • 1
  • 29
  • 46
  • I have two ngModule, If I include on child ngModule which is included in parent, then it does not work, but if I include it inside parent ngModule, then it starts working fine. Do you know how I can solve that? – Basit Sep 30 '16 at 17:14
  • ahh.. had to put it in `export: [MomentModule]` in order to fix it inside sub module. – Basit Sep 30 '16 at 17:17
0

Just inster in angular-cli.json at script array the path to moment.

"scripts": ["../node_modules/moment/moment.js"]
Yoav Schniederman
  • 5,253
  • 3
  • 28
  • 32