无法读取未定义的 属性 'schedule'
Cannot read property 'schedule' of undefined
所需的输出是 BsDatePicker 并且出于某种原因给我错误:无法读取 属性 'schedule' of undefined.
并且还有警告 BsDatepickerModule is under development,
突破性的改变是可能的,
请阅读更新日志
Angular-CLI 版本 1.7.4,ngx-bootstrap 版本 3.0.0,Angular 5
这是 html 的代码:
<input type="text" [(ngModel)]="dateOfBirth" name="dateOfBirth" id="dateOfBirth" bsDatepicker class="form-control"/>
这是 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 { }
这是我的应用程序-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 { }
这是我的。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",...
我认为 ngx-bootstrap 3.0.0 不是稳定版本。正如您在他们的文档站点中看到的那样。最新的稳定版本是 2.0.5。
document site
但是当你尝试通过命令安装它时:
npm install ngx-bootstrap --save
此命令将尝试获取最新版本 3.0.0。
所以,原因很简单,3.0.0目前还不是稳定版
版本 3.0.0 不稳定。获取最新的稳定版本 2.0.5
以下步骤有效。
rm -rf node_modules/ngx-bootstrap
package.json : "ngx-bootstrap": "^3.0.0"
到 "ngx-bootstrap": "2.0.5"
,
npm install ngx-bootstrap
我尝试了上述解决方案,对我来说效果很好
以下步骤:
package.json : "ngx-bootstrap": "^3.0.0" 到 "ngx-bootstrap": "2.0.5",
npm 安装 ngx-bootstrap
运行 服务器再次:ng serve
执行以下步骤即可解决问题:
Step 1: npm uninstall ngx-bootstrap
Step 2: npm install ngx-bootstrap@2.0.5 --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
所需的输出是 BsDatePicker 并且出于某种原因给我错误:无法读取 属性 'schedule' of undefined.
并且还有警告 BsDatepickerModule is under development,
突破性的改变是可能的,
请阅读更新日志
Angular-CLI 版本 1.7.4,ngx-bootstrap 版本 3.0.0,Angular 5
这是 html 的代码:
<input type="text" [(ngModel)]="dateOfBirth" name="dateOfBirth" id="dateOfBirth" bsDatepicker class="form-control"/>
这是 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 { }
这是我的应用程序-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 { }
这是我的。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",...
我认为 ngx-bootstrap 3.0.0 不是稳定版本。正如您在他们的文档站点中看到的那样。最新的稳定版本是 2.0.5。 document site 但是当你尝试通过命令安装它时:
npm install ngx-bootstrap --save
此命令将尝试获取最新版本 3.0.0。 所以,原因很简单,3.0.0目前还不是稳定版
版本 3.0.0 不稳定。获取最新的稳定版本 2.0.5
以下步骤有效。
rm -rf node_modules/ngx-bootstrap
package.json : "ngx-bootstrap": "^3.0.0"
到 "ngx-bootstrap": "2.0.5"
,
npm install ngx-bootstrap
我尝试了上述解决方案,对我来说效果很好
以下步骤:
package.json : "ngx-bootstrap": "^3.0.0" 到 "ngx-bootstrap": "2.0.5",
npm 安装 ngx-bootstrap
运行 服务器再次:ng serve
执行以下步骤即可解决问题:
Step 1: npm uninstall ngx-bootstrap
Step 2: npm install ngx-bootstrap@2.0.5 --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