在 Angular 6 中导入 "ngx-bootstrap/datepicker" 模块时出现错误
I'm getting an error while importing the "ngx-bootstrap/datepicker" module in Angular 6
我正在尝试在我的 Angular 应用程序中导入 ngx Bootstrap 日期选择器
为此,我遵循了以下镫骨
到 npm install ngx-bootstrap
npm install ngx-bootstrap --save
已安装 bootstrap 3
npm 安装bootstrap@3 --保存
在 angular-cli.json 文件中并在样式 属性 中指定 Bootstrap 样式表 (bootstrap.min.css) 的路径
"styles": [
"../node_modules/bootstrap/dist/css/bootstrap.min.css",
"styles.css"
]
在 Angular 中使用 ngx-bootstrap 日期选择器:
在app.module.ts文件中,导入BsDatepickerModule
从 'ngx-bootstrap/datepicker' 导入 { BsDatepickerModule };
在html中使用
bsDatepicker
class="form-control" />
在 .angular-cli.json 文件中包含对 bs-datepicker.css 文件的引用。
"styles": [
"../node_modules/bootstrap/dist/css/bootstrap.min.css",
"../node_modules/ngx-bootstrap/datepicker/bs-datepicker.css",
"styles.css"
]
but I am getting error while running the Angular Application
ERROR in multi ../node_modules/bootstrap/dist/css/bootstrap.min.css
../node_modules/ngx-bootstrap/datepicker/bs-datepicker.css
./src/styles.css
Module not found: Error: Can't resolve '/Users/user/Projects/node_modules/bootstrap/dist/css/bootstrap.min.css'
in '/Users/user/Projects/CRUD' ERROR in multi
../node_modules/bootstrap/dist/css/bootstrap.min.css
../node_modules/ngx-bootstrap/datepicker/bs-datepicker.css
./src/styles.css
Module not found: Error: Can't resolve '/Users/user/Projects/node_modules/ngx-bootstrap/datepicker/bs-datepicker.css'
in '/Users/user/Projects/CRUD'
我把代码的所有信息都放在下面-:
我把angular.json文件代码放在下面
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"CRUD": {
"root": "",
"sourceRoot": "src",
"projectType": "application",
"prefix": "app",
"schematics": {},
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/CRUD",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.app.json",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"../node_modules/bootstrap/dist/css/bootstrap.min.css",
"../node_modules/ngx-bootstrap/datepicker/bs-datepicker.css",
"src/styles.css"
],
"scripts": []
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "CRUD:build"
},
"configurations": {
"production": {
"browserTarget": "CRUD:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "CRUD:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.spec.json",
"karmaConfig": "src/karma.conf.js",
"styles": [
"src/styles.css"
],
"scripts": [],
"assets": [
"src/favicon.ico",
"src/assets"
]
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"src/tsconfig.app.json",
"src/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
},
"CRUD-e2e": {
"root": "e2e/",
"projectType": "application",
"architect": {
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "e2e/protractor.conf.js",
"devServerTarget": "CRUD:serve"
},
"configurations": {
"production": {
"devServerTarget": "CRUD:serve:production"
}
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": "e2e/tsconfig.e2e.json",
"exclude": [
"**/node_modules/**"
]
}
}
}
}
},
"defaultProject": "CRUD"
}
Package.json代码-:
{
"name": "crud",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^6.0.3",
"@angular/common": "^6.0.3",
"@angular/compiler": "^6.0.3",
"@angular/core": "^6.0.3",
"@angular/forms": "^6.0.3",
"@angular/http": "^6.0.3",
"@angular/platform-browser": "^6.0.3",
"@angular/platform-browser-dynamic": "^6.0.3",
"@angular/router": "^6.0.3",
"bootstrap": "^3.3.7",
"core-js": "^2.5.4",
"ngx-bootstrap": "^3.0.1",
"rxjs": "^6.0.0",
"zone.js": "^0.8.26"
},
"devDependencies": {
"@angular/compiler-cli": "^6.0.3",
"@angular-devkit/build-angular": "~0.6.8",
"typescript": "~2.7.2",
"@angular/cli": "~6.0.8",
"@angular/language-service": "^6.0.3",
"@types/jasmine": "~2.8.6",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "~4.2.1",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~1.7.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.0",
"karma-jasmine": "~1.1.1",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.3.0",
"ts-node": "~5.0.1",
"tslint": "~5.9.1"
}
}
App.module.ts代码
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { RouterModule , Routes } from '@angular/router';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { ListEmployeesComponent } from './employees/list-employees.component';
import { CreateEmployeeComponent } from './employees/create-employee.component';
import { BsDatepickerModule } from 'ngx-bootstrap/datepicker';
const appRoutes: Routes = [
{ path: 'list', component: ListEmployeesComponent },
{ path: 'create', component: CreateEmployeeComponent },
{ path: '', redirectTo: '/list', pathMatch: 'full' }
];
@NgModule({
declarations: [
AppComponent,
ListEmployeesComponent,
CreateEmployeeComponent
],
imports: [
BrowserModule,
RouterModule.forRoot(appRoutes),
FormsModule,
BsDatepickerModule.forRoot()
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
在我更正导入 css 文件位置后,我的错误得到修复。
我编辑了 angular.json
文件,如下所示
(remove ../: "styles": [ "node_modules/bootstrap/dist/css/bootstrap.min.css", "node_modules/ngx-bootstrap/datepicker/bs-datepicker.css", "src/styles.css" ],
您可以尝试使用这个命令:
ng add ngx-bootstrap
我有
@import "~ngx-bootstrap/datepicker/bs-datepicker";
我刚刚将其更改为:
@import "node_modules/ngx-bootstrap/datepicker/bs-datepicker";
我正在尝试在我的 Angular 应用程序中导入 ngx Bootstrap 日期选择器 为此,我遵循了以下镫骨
到 npm install ngx-bootstrap
npm install ngx-bootstrap --save
已安装 bootstrap 3
npm 安装bootstrap@3 --保存
在 angular-cli.json 文件中并在样式 属性 中指定 Bootstrap 样式表 (bootstrap.min.css) 的路径
"styles": [ "../node_modules/bootstrap/dist/css/bootstrap.min.css", "styles.css" ]
在 Angular 中使用 ngx-bootstrap 日期选择器:
在app.module.ts文件中,导入BsDatepickerModule
从 'ngx-bootstrap/datepicker' 导入 { BsDatepickerModule };
在html中使用
bsDatepicker
class="form-control" />
在 .angular-cli.json 文件中包含对 bs-datepicker.css 文件的引用。
"styles": [ "../node_modules/bootstrap/dist/css/bootstrap.min.css", "../node_modules/ngx-bootstrap/datepicker/bs-datepicker.css", "styles.css" ]
but I am getting error while running the Angular Application
ERROR in multi ../node_modules/bootstrap/dist/css/bootstrap.min.css
../node_modules/ngx-bootstrap/datepicker/bs-datepicker.css ./src/styles.css
Module not found: Error: Can't resolve '/Users/user/Projects/node_modules/bootstrap/dist/css/bootstrap.min.css'
in '/Users/user/Projects/CRUD' ERROR in multi ../node_modules/bootstrap/dist/css/bootstrap.min.css ../node_modules/ngx-bootstrap/datepicker/bs-datepicker.css ./src/styles.css
Module not found: Error: Can't resolve '/Users/user/Projects/node_modules/ngx-bootstrap/datepicker/bs-datepicker.css'
in '/Users/user/Projects/CRUD'
我把代码的所有信息都放在下面-:
我把angular.json文件代码放在下面
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"CRUD": {
"root": "",
"sourceRoot": "src",
"projectType": "application",
"prefix": "app",
"schematics": {},
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/CRUD",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.app.json",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"../node_modules/bootstrap/dist/css/bootstrap.min.css",
"../node_modules/ngx-bootstrap/datepicker/bs-datepicker.css",
"src/styles.css"
],
"scripts": []
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "CRUD:build"
},
"configurations": {
"production": {
"browserTarget": "CRUD:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "CRUD:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.spec.json",
"karmaConfig": "src/karma.conf.js",
"styles": [
"src/styles.css"
],
"scripts": [],
"assets": [
"src/favicon.ico",
"src/assets"
]
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"src/tsconfig.app.json",
"src/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
},
"CRUD-e2e": {
"root": "e2e/",
"projectType": "application",
"architect": {
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "e2e/protractor.conf.js",
"devServerTarget": "CRUD:serve"
},
"configurations": {
"production": {
"devServerTarget": "CRUD:serve:production"
}
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": "e2e/tsconfig.e2e.json",
"exclude": [
"**/node_modules/**"
]
}
}
}
}
},
"defaultProject": "CRUD"
}
Package.json代码-:
{
"name": "crud",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^6.0.3",
"@angular/common": "^6.0.3",
"@angular/compiler": "^6.0.3",
"@angular/core": "^6.0.3",
"@angular/forms": "^6.0.3",
"@angular/http": "^6.0.3",
"@angular/platform-browser": "^6.0.3",
"@angular/platform-browser-dynamic": "^6.0.3",
"@angular/router": "^6.0.3",
"bootstrap": "^3.3.7",
"core-js": "^2.5.4",
"ngx-bootstrap": "^3.0.1",
"rxjs": "^6.0.0",
"zone.js": "^0.8.26"
},
"devDependencies": {
"@angular/compiler-cli": "^6.0.3",
"@angular-devkit/build-angular": "~0.6.8",
"typescript": "~2.7.2",
"@angular/cli": "~6.0.8",
"@angular/language-service": "^6.0.3",
"@types/jasmine": "~2.8.6",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "~4.2.1",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~1.7.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.0",
"karma-jasmine": "~1.1.1",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.3.0",
"ts-node": "~5.0.1",
"tslint": "~5.9.1"
}
}
App.module.ts代码
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { RouterModule , Routes } from '@angular/router';
import { FormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
import { ListEmployeesComponent } from './employees/list-employees.component';
import { CreateEmployeeComponent } from './employees/create-employee.component';
import { BsDatepickerModule } from 'ngx-bootstrap/datepicker';
const appRoutes: Routes = [
{ path: 'list', component: ListEmployeesComponent },
{ path: 'create', component: CreateEmployeeComponent },
{ path: '', redirectTo: '/list', pathMatch: 'full' }
];
@NgModule({
declarations: [
AppComponent,
ListEmployeesComponent,
CreateEmployeeComponent
],
imports: [
BrowserModule,
RouterModule.forRoot(appRoutes),
FormsModule,
BsDatepickerModule.forRoot()
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
在我更正导入 css 文件位置后,我的错误得到修复。
我编辑了 angular.json
文件,如下所示
(remove ../: "styles": [ "node_modules/bootstrap/dist/css/bootstrap.min.css", "node_modules/ngx-bootstrap/datepicker/bs-datepicker.css", "src/styles.css" ],
您可以尝试使用这个命令:
ng add ngx-bootstrap
我有
@import "~ngx-bootstrap/datepicker/bs-datepicker";
我刚刚将其更改为:
@import "node_modules/ngx-bootstrap/datepicker/bs-datepicker";