1- import { Component } from '@angular/core' ;
1+ import { Component , Inject , OnInit , Renderer2 } from '@angular/core' ;
2+ import { DOCUMENT } from '@angular/platform-browser' ;
23import { editor } from 'monaco-editor' ;
4+ import { MonacoService } from 'projects/monaco-ng/src/public-api' ;
35
46@Component ( {
57 selector : 'app-root' ,
68 templateUrl : './app.component.html' ,
79 styleUrls : [ './app.component.scss' ]
810} )
9- export class AppComponent {
11+ export class AppComponent implements OnInit {
1012 title = 'monaco-ng' ;
13+ dark = false ;
1114
1215 editorOption : editor . IEditorConstructionOptions = {
1316 scrollBeyondLastLine : false ,
@@ -34,7 +37,28 @@ export class AppComponent {
3437 title = 'monaco-ng';
3538}` ;
3639
40+ constructor (
41+ private monacoService : MonacoService ,
42+ private renderer : Renderer2 ,
43+ @Inject ( DOCUMENT ) private document : any
44+ ) { }
45+
3746 onModelChange ( value : string ) : void {
3847 console . log ( value ) ;
3948 }
49+
50+ onToggleTheme ( ) : void {
51+ const next = this . dark ? 'vs-dark' : 'vs' ;
52+ this . monacoService . updateDefaultOption ( { theme : next } ) ;
53+ this . toggleBodyTheme ( ) ;
54+ }
55+
56+ toggleBodyTheme ( ) : void {
57+ this . renderer . addClass ( this . document . body , this . dark ? 'dark' : 'light' ) ;
58+ this . renderer . removeClass ( this . document . body , this . dark ? 'light' : 'dark' ) ;
59+ }
60+
61+ ngOnInit ( ) : void {
62+ this . toggleBodyTheme ( ) ;
63+ }
4064}
0 commit comments