Javascript SystemJS:使用捆绑文件更正System.import
我的bundle out.js文件连接了main.js和app.component.js模块。现在我想用SystemJS将这个out.js文件导入到index.html中。实际上,我想“调用”其中的主(.js)-模块 我现在想知道如何导入捆绑包文件的内部模块。将System.import(内部模块)嵌套在外部System.import(捆绑包)中是否正确?事实上,它正在工作,但我不确定这是否是好的 index.htmlJavascript SystemJS:使用捆绑文件更正System.import,javascript,angular,systemjs,Javascript,Angular,Systemjs,我的bundle out.js文件连接了main.js和app.component.js模块。现在我想用SystemJS将这个out.js文件导入到index.html中。实际上,我想“调用”其中的主(.js)-模块 我现在想知道如何导入捆绑包文件的内部模块。将System.import(内部模块)嵌套在外部System.import(捆绑包)中是否正确?事实上,它正在工作,但我不确定这是否是好的 index.html <script type="text/javascript" src=
<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
直接使用名称注册模块。因此,当您添加带有脚本标记的文件时,这些模块在SystemJS中直接可用
<script src="lib/out.js"></script>
<script>
System.import('main')
.then(null, console.error.bind(console));
</script>
System.import('main')
.then(null,console.error.bind(console));
使用您的命令,我在控制台中收到以下错误:异常:选择器“我的应用程序”与任何元素都不匹配您的HTML文件中是否仍有“我的应用程序”标记?是!我想我现在会接受那种解决办法。。谢谢你的帮助,非常感谢
<script src="lib/out.js"></script>
<script>
System.import('main')
.then(null, console.error.bind(console));
</script>