加载 ng2-bootstrap 时出错

Posted

技术标签:

【中文标题】加载 ng2-bootstrap 时出错【英文标题】:Error to load ng2-bootstrap 【发布时间】:2017-06-16 15:04:18 【问题描述】:

嗨,我导入 ng2-bootstrap 时出错,这是错误,嗨,我导入 ng2-bootstrap 时出错,这是错误,嗨,我导入 ng2-bootstrap 时出错,这是错误:

http://localhost:3002/ng2-bootstrap/ng2-bootstrap.js 404 (Not Found)
Error: Error: XHR error (404 Not Found) loading http://localhost:3002/ng2-bootstrap/ng2-bootstrap.js
    at XMLHttpRequest.wrapFn [as _onreadystatechange] (http://localhost:3002/node_modules/zone.js/dist/zone.js:698:29)
    at ZoneDelegate.invokeTask (http://localhost:3002/node_modules/zone.js/dist/zone.js:265:35)
    at Zone.runTask (http://localhost:3002/node_modules/zone.js/dist/zone.js:154:47)
    at XMLHttpRequest.ZoneTask.invoke (http://localhost:3002/node_modules/zone.js/dist/zone.js:335:33)
Error loading http://localhost:3002/ng2-bootstrap/ng2-bootstrap.js as "ng2-bootstrap" from http://localhost:3002/app/schedules/schedule-list.component.js

这里是 systmjs.config.js:

/**
* System configuration for Angular 2 samples
* Adjust as necessary for your application needs.
*/
(function (global) 
System.config(
    paths: 
        // paths serve as alias
        'npm:': 'node_modules/'
    ,
    // map tells the System loader where to look for things
    map: 
        // our app is within the app folder
        app: 'app',
        // angular bundles
        '@angular/core': 'npm:@angular/core/bundles/core.umd.js',
        '@angular/common': 'npm:@angular/common/bundles/common.umd.js',
        '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
        '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
        '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
        '@angular/http': 'npm:@angular/http/bundles/http.umd.js',
        '@angular/router': 'npm:@angular/router/bundles/router.umd.js',
        '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
        // other libraries
        'rxjs': 'npm:rxjs',
        'angular-in-memory-web-api': 'npm:angular-in-memory-web-api',
        'jquery': 'npm:jquery/',
        'lodash': 'npm:lodash/lodash.js',

        'ng2-bootstrap/ng2-bootstrap': 'node_modules/ng2-bootstrap/bundles/ng2-bootstrap.umd.js',
        'moment': 'node_modules/moment/moment.js',
        'symbol-observable': 'npm:symbol-observable'
    ,
    // packages tells the System loader how to load when no filename and/or no extension
    packages: 
        app: 
            main: './main.js',
            defaultExtension: 'js'
        ,
        rxjs: 
            defaultExtension: 'js'
        ,
        'angular-in-memory-web-api': 
            main: './index.js',
            defaultExtension: 'js'
        ,
        'moment':  main: 'moment.js', defaultExtension: 'js' ,
        'ng2-bootstrap':  main: 'ng2-bootstrap.js', defaultExtension: 'js' ,
        'symbol-observable':  main: 'index.js', defaultExtension: 'js' 
    
);
 )(this);

package.json


 "version": "1.0.0",
 "name": "scheduler",

“作者”:“克里斯·萨克拉里奥斯”, “许可证”:“麻省理工学院”, "存储库": "https://github.com/chsakell/angular2-features", “私人”:真的, “依赖”: "@angular/common": "2.0.0", "@angular/compiler": "2.0.0", "@angular/core": "2.0.0", "@angular/forms": "2.0.0", "@angular/http": "2.0.0", "@angular/platform-b​​rowser": "2.0.0", "@angular/platform-b​​rowser-dynamic": "2.0.0", "@angular/路由器": "3.0.0", “@angular/升级”:“2.0.0”, "引导程序": "^3.3.6",

"jquery": "^3.0.0",
"lodash": "^4.13.1",
"moment": "^2.13.0",
"ng2-bootstrap": "^1.1.5",
"ng2-slim-loading-bar": "1.5.1",

"core-js": "^2.4.1",
"reflect-metadata": "^0.1.3",
"rxjs": "5.0.0-beta.12",
"systemjs": "0.19.27",
"zone.js": "^0.6.23",
"angular2-in-memory-web-api": "0.0.20"
 ,
"devDependencies": 
"concurrently": "^2.0.0",
"del": "^2.2.0",
"gulp": "^3.9.1",
"gulp-tslint": "^5.0.0",
"jquery": "^3.0.0",
"lite-server": "^2.2.0",
"typescript": "2.0.2",
"typings": "^1.3.2",
"tslint": "^3.10.2"
 ,
 "scripts": 
"start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite --baseDir ./app --port 8000\" ",
"lite": "lite-server",
"postinstall": "typings install",
"tsc": "tsc",
"tsc:w": "tsc -w",
"typings": "typings"


【问题讨论】:

你有错误的url,因此404结果代码。 谢谢你的回答,但在哪里?? 从 'ng2-bootstrap' 导入 ModalDirective ;这是我在 schedule-list.component.js 中的导入 那么您认为这段代码在做什么?或者 import 语句中的“ng2-bootstrap”是什么? 在你的路径中:'moment': 'node_modules/moment/moment.js', 'ng2-bootstrap': 'node_modules/ng2-bootstrap/ng2-bootstrap.js', 【参考方案1】:

在你的路径对象中:

'moment':  main: 'moment.js', defaultExtension: 'js' ,
'ng2-bootstrap':  main: 'ng2-bootstrap.js', defaultExtension: 'js' 

在你的包对象中:

'moment':  main: 'moment.js', defaultExtension: 'js' ,
'ng2-bootstrap':  main: 'ng2-bootstrap.js', defaultExtension: 'js' ,

【讨论】:

谢谢你..我做了你上面提到的但没有用 看上面 尝试 'ng2-bootstrap': 'node_modules/ng2-bootstrap/ng2-bootstrap.js' 没有捆绑包【参考方案2】:

ng-2 bootstrap:此包已弃用,已重命名为ngx-bootstrap

尝试使用 npm 安装 ngx-bootstrap

npm i ngx-bootstrap --save

【讨论】:

以上是关于加载 ng2-bootstrap 时出错的主要内容,如果未能解决你的问题,请参考以下文章

运行 Spring Boot 应用程序时出错

在 Spring Boot 中创建自定义查询时出错

构建spring boot项目时出错[重复]

在 spring-boot 中使用 @EnableWebFluxSecurity 时出错

Spring Boot - “创建名为 'entityManagerFactory' 的 bean 时出错” - 开始

Spring Boot - “创建名为 'entityManagerFactory' 的 bean 时出错” - 开始