【问题标题】:ES6 -- importing of es5 filesES6 -- es5 文件的导入
【发布时间】:2015-03-18 21:38:31
【问题描述】:

我尝试使用此 (https://github.com/gocardless/es6-angularjs/blob/master/README.md) 作为起点,然后包含 bootstrap javascript 代码。为了打开一个模态

但唯一会发生的是:

Potentially unhandled rejection [3] Error loading "components/bootstrap/dist/js" at http://localhost:3010/components/bootstrap/dist/js.js
Error loading "components/bootstrap/dist/js" from "app-compiled/bootstrap" at http://localhost:3010/app-compiled/bootstrap.js
Not Found: http://localhost:3010/components/bootstrap/dist/js.js (WARNING: non-Error used)

我在 main.js 中添加了这个:

import 'bootstrap-js';
//TODO please explain to me why not working

这个到 loader.config.js 文件:

System.config({
  meta: {

    ...,
    'components/bootstrap/dist/js':{ format: 'global', export: 'bootstrap'}


  },
  map: {

    ....,
    'bootstrap-js': 'components/bootstrap/dist/js'

  }
});

【问题讨论】:

    标签: javascript angularjs twitter-bootstrap ecmascript-6 gocardless


    【解决方案1】:
    1. 在这里尝试exports 而不是export
    System.config({
        meta: {
        //...
            'components/bootstrap/dist/js':{ format: 'global', exports: 'bootstrap'}
        }
        //...
    });
    
    1. 当您写入{ format: 'global', exports: 'bootstrap'} 时,您正在尝试获取全局bootstrap 变量。但这样的不存在。所以我认为你必须删除元线并修复地图。结果必须如下所示:
    System.config({
        meta: {
            //...
            'components/path/to/jquery': { format: 'global', exports: 'jQuery' },
            'components/bootstrap/dist/js/bootstrap': { deps: ['jquery'] }
        }
        map: {
            //...
            'jquery': 'components/path/to/jquery',
            'bootstrap-js': 'components/bootstrap/dist/js/bootstrap'
        }
    });
    

    【讨论】:

    • 似乎仍然不起作用我什至尝试输入确切的路径,例如:/components/bootstrap/dist/js/bootstrap.min.js ----> dropbox.com/sh/igta72ltvuk90m8/AAD9Pdku4aXET2sifBscJ6mxa?dl=0
    • @geoHeil 好吧,我想我明白你的问题了。当您编写 { format: 'global', exports: 'bootstrap'} 时,您正在尝试获取全局 bootstrap 变量。但这样的不存在
    • 嗨,这似乎是正确的:现在我得到:可能未处理的拒绝 [2] 评估 localhost:3010/components/bootstrap/dist/js/bootstrap.js 时出错:未捕获的错误:Bootstrap 的 JavaScript 需要 jQuery(警告:使用非错误)
    • @geoHeil 我认为您必须将 jquery 添加到您的包中并指定对引导程序的依赖关系。所以我更新了答案。我希望这会有所帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-03-21
    • 1970-01-01
    • 2016-04-09
    • 2016-08-09
    • 2021-08-23
    • 1970-01-01
    • 2019-09-21
    相关资源
    最近更新 更多