【问题标题】:SystemJS: Correct System.import with bundle-fileSystemJS:使用捆绑文件更正 System.import
【发布时间】:2016-03-26 03:25:00
【问题描述】:

我的 bundle out.js 文件连接了一个 main.js 和一个 app.component.js 模块。现在我想用 SystemJS 在我的 index.html 中导入这个 out.js 文件。其实我想在里面“调用”main(.js)-module。

我现在想知道如何导入我的捆绑文件的内部模块。将 System.import (内部模块)嵌套在外部 System.import (捆绑)中是否正确?实际上它正在工作,但我不确定这是否可以。

index.html

<script type="text/javascript" src="lib/out.js"></script>

<script>
    System.config({
        packages: {
            lib: {
                format: 'register',
                defaultExtension: 'js'
            }
        }
    });
    System.import('lib/out')
            .then(function() { // ---Is this the way to do it?---
                System.import('/main');
            }, console.error.bind(console));
</script>

out.js

System.register('app.component', ['angular2/core'], function(exports_1, context_1) {
  var __moduleName = context_1 && context_1.id;
  ..
}};

System.register('main', ['angular2/platform/browser', './app.component'], function(exports_1, context_1) {
  var __moduleName = context_1 && context_1.id;    
  ..
}};

【问题讨论】:

    标签: javascript angular systemjs


    【解决方案1】:

    事实上,您的out.js 文件使用System.register 直接使用名称注册您的模块。因此,当您使用脚本标记添加此文件时,这些模块可以直接在 SystemJS 中使用。

    <script src="lib/out.js"></script>
    
    <script>
      System.import('main')
            .then(null, console.error.bind(console));
    </script>
    

    【讨论】:

    • 使用您的命令,我在控制台中收到以下错误:异常:选择器“my-app”与任何元素都不匹配
    • 您的 HTML 文件中是否还有“my-app”标签?
    • 是的!我想我现在会接受这种解决方法。感谢您的帮助,非常感谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-05
    • 1970-01-01
    • 2018-07-22
    • 2016-09-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多