Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Unexpected module 'DatePickerModule' declared by the module 'AppModule'. Please add a @Pipe/@Directive/@Component annotation

I want to use DatePickerModule of Angular in my application. So I have installed the package as follows: npm install ng2-datepicker-bootstrap --save

Installation was successful. So now, I imported the DatePickerModule module in my AppModule as shown below:

import { DatePickerModule } from 'ng2-datepicker-bootstrap';

@NgModule({

  declarations: [
    other Components......,
    DatePickerModule
  ],
  imports: [
    ........
  ],
  providers: [Service, DatePickerModule],
  bootstrap: [AppComponent]
})

export class AppModule { }

Then use the code below in my info.component.html.

<datepicker [(ngModel)]="model.firstDate" [viewFormat]="'DD/MM/YYYY'" [modelFormat]="'YYYY-MM-DD'"  [id]="'firstDate'" [label]="'To'"></datepicker> 

But when I run the project I got this error : Error: Unexpected module 'DatePickerModule' declared by the module 'AppModule'. Please add a @Pipe/@Directive/@Component annotation.

I am new to Angular2 by the way.

like image 628
wal Avatar asked May 02 '17 01:05

wal


1 Answers

Why are you putting your DatePickerModule in providers. Only services needs to be put in there angular create the instance of the service when the application is bootstrapped.

like image 188
Usman Hussain Avatar answered Oct 18 '22 15:10

Usman Hussain