我有以下代码在我的angularjs网站的index.html
中加载摩纳哥的代码:
<link rel="stylesheet" data-name="vs/editor/editor.main" href="/monaco-editor/min/vs/editor/editor.main.css" />
<script src="/monaco-editor/min/vs/loader.js"></script>
<script src="/monaco-editor/min/vs/editor/editor.main.nls.js"></script>
<script src="/monaco-editor/min/vs/editor/editor.main.js"></script>
<script>
require.config({ paths: { 'vs': '/monaco-editor/min/vs' }})
console.log(monaco)
</script>
运行网站显示良好的monaco
,该网站将在其他JavaScript文件中使用。
现在,我想通过 ocLazyLoad
加载摩纳哥鞋:
.state('addin', {
abstract: true,
template: '<ui-view/>',
resolve: {
loadAddinCtrl: ['$ocLazyLoad', function ($ocLazyLoad) {
return $ocLazyLoad.load({files: [
"/monaco-editor/min/vs/editor/editor.main.css",
"/monaco-editor/min/vs/loader.js",
"/monaco-editor/min/vs/editor/editor.main.nls.js",
"/monaco-editor/min/vs/editor/editor.main.js"
]}).then(function () {
require.config({ paths: { 'vs': '/monaco-editor/min/vs' }})
console.log(monaco)
})
}]
}
})
以上代码返回ReferenceError: monaco is not defined
。有人知道为什么会发生这种情况吗?
实际上,我不太了解require.config
的目的,它似乎会使代码变得更加灵活。有人有选择吗?
您已经加载了依赖项,但没有加载摩纳哥。在您的require.config
之后尝试一下:
require.config({ paths: { 'vs': '/monaco-editor/min/vs' }})
require(['vs/editor/editor.main'], function onMonacoLoaded(){
console.log(monaco);
});