Search code examples
angularmomentjsangular2-moment

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 the import in my app.module.ts file:

import { MomentModule } from 'angular2-moment';

included it in my module declarations and entry components array, ran the build and got:

"Error: Unexpected module 'MomentModule' declared by the module 'AppModule' "


Solution

  • import { BrowserModule  } from '@angular/platform-browser';
    import {MomentModule} from 'angular2-moment';
    @NgModule({
        declarations:[/**...**/]
        imports:      [BrowserModule,MomentModule], // did you update this line this works for me 
        bootstrap:    [AppComponent],
        providers:[
           /**
           ...
    
           **/
        ]
    })
    

    This works check this link https://github.com/rahulrsingh09/AngularConcepts/blob/master/src/app/app.module.ts line 115