Search code examples
angularangular5web-frontendngx-bootstrap

Cannot read property 'schedule' of undefined


The desired output is the BsDatePicker and for some reason is giving me the error: Cannot read property 'schedule' of undefined.
and also have the warning BsDatepickerModule is under development, BREAKING CHANGES are possible, PLEASE, read changelog

Angular-CLI version 1.7.4, ngx-bootstrap version 3.0.0, Angular 5

This is the code of the html:
<input type="text" [(ngModel)]="dateOfBirth" name="dateOfBirth" id="dateOfBirth" bsDatepicker class="form-control"/>

This is the code of the app.module.ts:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { BsDatepickerModule } from 'ngx-bootstrap/datepicker';
import { AppRoutingModule } from './app-routing.module';

import { AppComponent } from './app.component';
import { HomeComponent } from './home/home.component';
import { PageNotFoundComponent } from './page-not-found/page-not-found.component';
import { CreateEmployeeComponent } from './employee/create-employee/create-employee.component';


@NgModule({
  declarations: [
    AppComponent,
    HomeComponent,
    CreateEmployeeComponent,
    PageNotFoundComponent 
  ],
  imports: [
    BrowserModule,
    FormsModule,
    BsDatepickerModule.forRoot(),
    AppRoutingModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }



This is my app-routing.module.ts

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { HomeComponent } from './home/home.component';
import { PageNotFoundComponent } from './page-not-found/page-not-found.component';
import { CreateEmployeeComponent } from './employee/create-employee/create-employee.component';

const routes: Routes = [
   { path : 'home' , component : HomeComponent},
   { path : 'createEmployee', component : CreateEmployeeComponent},
   { path : '', redirectTo: '/home', pathMatch : 'full'},
   { path : '**', component: PageNotFoundComponent}
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }



And this is my .angular-cli.json

..."testTsconfig": "tsconfig.spec.json",
      "prefix": "app",
      "styles": [
        "../node_modules/bootstrap/dist/css/bootstrap.min.css",
        "../node_modules/ngx-bootstrap/datepicker/bs-datepicker.css",
        "styles.css"
      ],
      "scripts": [
        "../node_modules/jquery/dist/jquery.slim.min.js",
        "../node_modules/popper.js/dist/umd/popper.min.js",
        "../node_modules/bootstrap/dist/js/bootstrap.min.js"
      ],
      "environmentSource": "environments/environment.ts",...

Solution

  • Perform the below steps and it will fix the issue:

    Step 1: npm uninstall ngx-bootstrap
    
    Step 2: npm install [email protected] --save 
    
    Step 3: ng serve
    
    Step 4: Add the css file path "../node_modules/ngx-bootstrap/datepicker/bs-datepicker.css" in styles array in angular-cli.json file