代码之家  ›  专栏  ›  技术社区  ›  SoftTimur

无法隐藏Monaco编辑器

  •  0
  • SoftTimur  · 技术社区  · 7 年前

    我的页面上有一位摩纳哥编辑。现在,我需要不时隐藏/显示它。但我意识到,它在 ng-show , ng-hide ng-if . 有人有解决方案吗?

    https://jsbin.com/mepupagisi/4/edit?html,output

    <!DOCTYPE html>
    <html>
    <head>
        <script src="https://code.jquery.com/jquery.min.js"></script>
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
    </head>
    <body>
        <div ng-show="true">
            <div id="container"></div>
        </div>
        <script src="https://www.matrixlead.com/monaco-editor/min/vs/loader.js"></script>
        <script>
            require.config({ paths: { 'vs': 'https://www.matrixlead.com/monaco-editor/min/vs' }})
    
            require(["vs/editor/editor.main"], function () {
              var editor = monaco.editor.create(document.getElementById('container'), {
                value: 'function x() {\n\tconsole.log("Hello world!");\n}',
                language: 'javascript',
                minimap: { enabled: false },
                scrollBeyondLastLine: false
              });
            });
        </script>
    </body>
    </html>
    

    编辑1: 我仍然看到一条细线:

    enter image description here

    1 回复  |  直到 7 年前
        1
  •  0
  •   Tsvetan Ganev    7 年前

    为了使用AngularJS指令,首先必须通过添加 ng-app 属性设置为容器元素。例如:

    <body ng-app>
      <div ng-hide="true">
        Will be hidden
      </div>
    </body>
    

    现在,您可以使用body标记中的所有内置AngularJS指令。

    这是一个工作 JSBin demo . 查看 ng-hide=true 隐藏Monaco编辑器。删除该指令或将其更改为 ng-hide=false 再次显示。