File

src/ngx-monaco-editor/src/lib/directives/monaco-editor-loader.directive.ts

Implements

OnInit OnDestroy

Metadata

Index

Properties
Methods

Constructor

constructor(templateRef: TemplateRef, viewContainer: ViewContainerRef, monacoEditorLoaderService: MonacoEditorLoaderService)
Parameters :
Name Type Optional
templateRef TemplateRef<any> No
viewContainer ViewContainerRef No
monacoEditorLoaderService MonacoEditorLoaderService No

Methods

ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void

Properties

destroyed$
Default value : new Subject<void>()
isMonacoLoaded$
Default value : this.monacoEditorLoaderService.isMonacoLoaded$.asObservable()
import { Directive, TemplateRef, ViewContainerRef, OnDestroy, OnInit } from '@angular/core';
import { MonacoEditorLoaderService } from '../services/monaco-editor-loader.service';
import { takeUntil } from 'rxjs/operators';
import { Subject } from 'rxjs';

@Directive({ selector: '[ngxLoadMonacoEditor]' })
export class MonacoEditorLoaderDirective implements OnInit, OnDestroy {
  isMonacoLoaded$ = this.monacoEditorLoaderService.isMonacoLoaded$.asObservable();
  destroyed$ = new Subject<void>();

  constructor(
    private templateRef: TemplateRef<any>,
    private viewContainer: ViewContainerRef,
    private monacoEditorLoaderService: MonacoEditorLoaderService
  ) {}

  ngOnInit() {
    this.isMonacoLoaded$.pipe(takeUntil(this.destroyed$)).subscribe((loaded) => {
      if (!loaded) {
        return this.viewContainer.clear();
      }
      this.viewContainer.createEmbeddedView(this.templateRef);
    });
  }

  ngOnDestroy() {
    this.destroyed$.next();
    this.destroyed$.complete();
  }
}

results matching ""

    No results matching ""