diff --git a/verify/angular/src/app/app.component.css b/verify/angular/src/app/app.component.css deleted file mode 100644 index 3a7e0476d..000000000 --- a/verify/angular/src/app/app.component.css +++ /dev/null @@ -1,3 +0,0 @@ -.monaco-editor { - height: 50vh; -} diff --git a/verify/angular/src/app/app.component.html b/verify/angular/src/app/app.component.html index 4a0cddd60..c5c54137d 100644 --- a/verify/angular/src/app/app.component.html +++ b/verify/angular/src/app/app.component.html @@ -1,12 +1,11 @@ -

Monaco Language Client Angular Client Two way data binding Example

-
- @if(wrapperConfig) { +

Angular Monaco Editor demo with saving code to a mock HTTP server

+
- } - - {{ codeText() }} +
diff --git a/verify/angular/src/app/app.component.scss b/verify/angular/src/app/app.component.scss new file mode 100644 index 000000000..e69de29bb diff --git a/verify/angular/src/app/app.component.ts b/verify/angular/src/app/app.component.ts index 2675e6d78..6875a7e31 100644 --- a/verify/angular/src/app/app.component.ts +++ b/verify/angular/src/app/app.component.ts @@ -3,31 +3,50 @@ * Licensed under the MIT License. See LICENSE in the package root for license information. * ------------------------------------------------------------------------------------------ */ -import { AfterViewInit, Component, signal } from '@angular/core'; +import { AfterViewInit, Component, inject, signal } from '@angular/core'; import { WrapperConfig } from 'monaco-editor-wrapper'; -import { MonacoAngularWrapperComponent } from '../monaco-angular-wrapper.component'; +import { MonacoAngularWrapperComponent } from '../monaco-angular-wrapper/monaco-angular-wrapper.component'; import { buildJsonClientUserConfig } from 'monaco-languageclient-examples/json-client'; +import { SaveCodeService } from '../save-code.service'; +import { firstValueFrom } from 'rxjs'; @Component({ selector: 'app-root', - templateUrl: './app.component.html', - styleUrls: ['./app.component.css'], + templateUrl: "./app.component.html", + styleUrls: ["./app.component.scss"], standalone: true, imports: [MonacoAngularWrapperComponent], }) export class AppComponent implements AfterViewInit { - wrapperConfig: WrapperConfig | undefined; - title = 'angular-client'; + private saveCodeService = inject(SaveCodeService); + wrapperConfig = signal(undefined); // this can be updated at runtime + title = 'angular demo for saving code'; + editorId = 'monaco-editor-root'; // this can be parameterized or it can be in a loop to support multiple editors + editorInlineStyle = signal('height: 50vh;'); readonly codeText = signal(''); async ngAfterViewInit(): Promise { - const config = buildJsonClientUserConfig({ - htmlContainer: document.getElementById('monaco-editor-root')!, - }); - this.wrapperConfig = config; + const editorDom = document.getElementById(this.editorId); + if (editorDom) { + const config = buildJsonClientUserConfig({ + htmlContainer: editorDom, + }); + this.wrapperConfig.set(config); + } } onTextChanged(text: string) { this.codeText.set(text); } + + save = async () => { + try { + const response = await firstValueFrom( + this.saveCodeService.saveCode(this.codeText()) + ); + alert('Code saved:' + JSON.stringify(response)); + } catch (error) { + console.error('Error saving code:', error); + } + }; } diff --git a/verify/angular/src/main.ts b/verify/angular/src/main.ts index 8cf61032f..0096b59db 100644 --- a/verify/angular/src/main.ts +++ b/verify/angular/src/main.ts @@ -4,5 +4,8 @@ * ------------------------------------------------------------------------------------------ */ import { bootstrapApplication } from '@angular/platform-browser'; +import { provideHttpClient } from '@angular/common/http'; import { AppComponent } from './app/app.component'; -bootstrapApplication(AppComponent); +bootstrapApplication(AppComponent, { + providers: [provideHttpClient()], +}); diff --git a/verify/angular/src/save-code.service.ts b/verify/angular/src/save-code.service.ts new file mode 100644 index 000000000..0f0387d88 --- /dev/null +++ b/verify/angular/src/save-code.service.ts @@ -0,0 +1,9 @@ +import { inject, Injectable } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; +@Injectable({ providedIn: 'root' }) +export class SaveCodeService { + private http = inject(HttpClient); + saveCode(codeText: string) { + return this.http.post('http://localhost:3003/save-code', { code: codeText }); + } +}