简体   繁体   English

AngularJS 中的 monaco 编辑器

[英]monaco-editor in AngularJS

I am able to implement monaco-editor in AngularJS but in case if user refresh the page monaco through an error saying that "monaco is not defined" this is because monaco is loading lazy.Is there any other way monaco can load immediately.我能够在 AngularJS 中实现 monaco-editor,但如果用户通过错误提示“m​​onaco 未定义”刷新页面 monaco,这是因为 monaco 正在加载懒惰。是否有其他方式 monaco 可以立即加载。 Here is the code..这是代码..

 resolve: {
            srcipts: function (lazyScript) {
               return lazyScript.register([
                      "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 () {
                        // console.log(require);
                     require.config({ paths: { 'vs': 'monaco-editor/min/vs' } })
                         // console.log(monaco)
                         })
                     }
               }

this are the link to i refereed这是我推荐的链接

Lazy-load MonacoEditor 延迟加载 MonacoEditor

https://github.com/Microsoft/monaco-editor/blob/master/docs/integrate-amd.md https://github.com/Microsoft/monaco-editor/blob/master/docs/integrate-amd.md

https://microsoft.github.io/monaco-editor/playground.html https://microsoft.github.io/monaco-editor/playground.html

help me with this issue帮我解决这个问题

This isn't exactly the answer you were looking for, but I had the same problem with monaco in Angular 1.x.这不是您正在寻找的答案,但我在 Angular 1.x 中遇到了与 monaco 相同的问题。 I ended up implementing monaco inside of an iFrame.我最终在 iFrame 中实现了 monaco。 Makes it a bit difficult, but it loads much easier than with AMD loading.让它有点困难,但加载比使用 AMD 加载要容易得多。

I know it's far from an ideal solution, but I basically ended up doing the following in a Directive that wraps the editor.我知道这远非理想的解决方案,但我基本上最终在包含编辑器的指令中执行以下操作。

function delayedInitialization() {
  if (typeof window.monaco === 'undefined') {
    $timeout(delayedInitialization, 200);
  } else {
    initialize();
  }
}

One could perhaps make that a bit cleaner by packaging the editor in a way that allowed to listen for an event of sorts, but for now this works for our need.也许可以通过以一种允许侦听某种事件的方式打包编辑器来使之更简洁,但现在这可以满足我们的需要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM