내용으로 건너뛰기
GaramX
사용자 도구
로그인
사이트 도구
검색
도구
문서 보기
이전 판
역링크
최근 바뀜
미디어 관리자
사이트맵
로그인
>
최근 바뀜
미디어 관리자
사이트맵
현재 위치:
home
»
monaco-editor
추적:
monaco-editor
이 문서는 읽기 전용입니다. 원본을 볼 수는 있지만 바꿀 수는 없습니다. 문제가 있다고 생각하면 관리자에게 문의하세요.
====== Microsoft Monaco Editor ====== * [[study:monaco_editor|Microsoft Monaco Editor]] ===== Angular 자료교환 ===== 이것을 별도참조 atularen/ngx-monaco-editor. ===== Angular App ===== <code bash> npm install monaco-editor </code> <code json angular.json> "assets": [ ... { "glob": "**/*", "input": "node_modules/monaco-editor", "output": "assets/monaco-editor" } ], </code> <code javascript monaco-editor-service.ts> import { Injectable } from '@angular/core'; import { Subject } from 'rxjs'; @Injectable({ providedIn: 'root', }) export class MonacoEditorService { loaded: boolean = false; public loadingFinished: Subject<void> = new Subject<void>(); constructor() {} private finishLoading() { this.loaded = true; this.loadingFinished.next(); } public load() { // load the assets const baseUrl = './assets' + '/monaco-editor/min/vs'; if (typeof (<any>window).monaco === 'object') { this.finishLoading(); return; } const onGotAmdLoader: any = () => { // load Monaco (<any>window).require.config({ paths: { vs: `${baseUrl}` } }); (<any>window).require([`vs/editor/editor.main`], () => { this.finishLoading(); }); }; // load AMD loader, if necessary if (!(<any>window).require) { const loaderScript: HTMLScriptElement = document.createElement('script'); loaderScript.type = 'text/javascript'; loaderScript.src = `${baseUrl}/loader.js`; loaderScript.addEventListener('load', onGotAmdLoader); document.body.appendChild(loaderScript); } else { onGotAmdLoader(); } } } </code> Now call monacoEditorService.load(), as soon as you need the editor (in my case it's called in app.component.ts in the constructor, to make the editor always available and already preload it). Now, you can create editors as you please, but make sure to not create them, before Monaco is loaded yet. Like this: <code javascript monaco-editor.component.ts> import ... declare var monaco: any; @Component({ selector: 'app-monaco-editor', templateUrl: './monaco-editor.component.html', styleUrls: ['./monaco-editor.component.scss'], }) export class MonacoEditorComponent implements OnInit, OnDestroy, AfterViewInit { public _editor: any; @ViewChild('editorContainer', { static: true }) _editorContainer: ElementRef; private initMonaco(): void { if(!this.monacoEditorService.loaded) { this.monacoEditorService.loadingFinished.pipe(first()).subscribe(() => { this.initMonaco(); }); return; } this._editor = monaco.editor.create( this._editorContainer.nativeElement, options ); } ngAfterViewInit(): void { this.initMonaco(); } </code> There are most probably more elegant solutions than a boolean flag and this subject. Make sure, there is a div in the component, like this: <code html monaco-editor.component.html> <div class="editor-container" #editorContainer></div> </code>
monaco-editor.txt
· 마지막으로 수정됨: 2025/04/15 10:05 저자
127.0.0.1
문서 도구
문서 보기
이전 판
역링크
맨 위로