@postfinance/ngx-ace-editor-wrapper
TypeScript icon, indicating that this package has built-in type declarations

11.1.2 • Public • Published

@postfinance/ngx-ace-editor-wrapper

Ace editor integration with TypeScript for Angular 10.

Blazing Fast License: Apache 2

Examples

There is a live example available on GitHub Pages.

Installation

npm i @postfinance/ngx-ace-editor-wrapper

Loading the module:

import { AceEditorModule } from '@postfinance/ngx-ace-editor-wrapper';

@NgModule({
  ...
  imports: [
    ...
    AceEditorModule
  ]
})

Usage

Directive

Minimal

// import { AceEditorModule } from '@postfinance/ngx-ace-editor-wrapper';

import { Component } from '@angular/core'

@Component({
  template: ` <div ngxAceEditor [(text)]="text"></div> `,
})
export class MyComponent {
  text: string = ''
}

Complete

import { Component } from '@angular/core'

// Imports are important! You may configure it via `angular.json` as well.
import 'brace'
import 'brace/mode/sql'
import 'brace/theme/eclipse'

@Component({
  template: `
  <div ngxAceEditor
      [(text)]="text" // possible two way binding (thx ChrisProlls)
      [mode]="'sql'" //string or object (thx ckiffel)
      [theme]="'eclipse'"
      [options]="options"
      [readOnly]="false"
      [autoUpdateContent]="true" //change content when [text] change
      [durationBeforeCallback]="1000" //wait 1s before callback 'textChanged' sends new value
      (textChanged)="onChange($event)"
      style="min-height: 200px; width:100%; overflow: auto;">
  </div>
  `,
})
export class MyComponent {
  text: string = ''
  options: any = { maxLines: 1000, printMargin: false }

  onChange(code) {
    console.log('new code', code)
  }
}

Component

import { Component, ViewChild } from '@angular/core'

import { AceEditorComponent } from '@postfinance/ngx-ace-editor-wrapper'

// Imports are important!
import 'brace'

@Component({
  template: `
    <ngx-ace-editor #editor [(text)]="text" style="height:150px;">
    </ngx-ace-editor>
  `,
})
export class AceCmp {
  @ViewChild(AceEditorComponent)
  editor

  text: string = ''

  ngAfterViewInit() {
    this.editor.setTheme('eclipse')

    this.editor.getEditor().setOptions({
      enableBasicAutocompletion: true,
    })

    this.editor.getEditor().commands.addCommand({
      name: 'showOtherCompletions',
      bindKey: 'Ctrl-.',
      exec: function (editor) {},
    })
  }
}

Hat Tips

License

This project is licensed under the terms of the Apache 2.0 License.

Readme

Keywords

none

Package Sidebar

Install

npm i @postfinance/ngx-ace-editor-wrapper

Weekly Downloads

88

Version

11.1.2

License

Apache-2.0

Unpacked Size

201 kB

Total Files

19

Last publish

Collaborators

  • bbortt