atularen / ngx-monaco-editor

Monaco Editor component for Angular 2 and Above
https://www.npmjs.com/package/ngx-monaco-editor
MIT License
428 stars 155 forks source link

Why I can not use window.require in my self code? #108

Closed AiHaibara closed 5 years ago

AiHaibara commented 5 years ago

I'm a rookie. I want to use monaco-editor(not ngx-monaco-editor) for a simple angular web demo (just for study). Can you tell me why window.require is not a function? why you can use window.require? Can you give me some advice?

declare const require: any;

 (<any>window).require.config({ paths: { 'vs': '../node_modules/monaco-editor/min/vs' }});

     (<any>window).require(['vs/editor/editor.main'], function() {
      var editor = monaco.editor.create(document.getElementById('container'), {
        value: [
          'function x() {',
          '\tconsole.log("Hello world!");',
          '}'
        ].join('\n'),
        language: 'javascript'
      });
    });
AiHaibara commented 5 years ago

I'm sorry I don't have to write window.require(), just use require()