angular-ace-editor
TypeScript icon, indicating that this package has built-in type declarations

0.2.3 • Public • Published

ng2-ace-editor

npm version Ace editor integration with typescript for angular 2.

Install

npm i -S ng2-ace-editor

Use directive

Minimal

//add "AceEditorDirective" to your modules list
 
import { Component } from '@angular/core';
 
@Component({
  template: `
  <div ace-editor
       [(text)]="text" // possible two way binding (thx ChrisProlls)
       ></div>
  `
})
export class MyComponent {
    text:string = "";
}

Complete

//add "AceEditorDirective" to your modules list
//import { AceEditorDirective } from 'ng2-ace-editor';
 
import { Component } from '@angular/core';
 
//to use theme "eclipse"
//with angular-cli add "../node_modules/ace-builds/src-min/ace.js" 
//and "../node_modules/ace-builds/src-min/theme-eclipse.js" to "scripts" var into the file angular-cli.json
 
@Component({
  template: `
  <div ace-editor
       [(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);
    }
}

Use Component

//add "AceEditorComponent" to your modules list
//import { AceEditorComponent } from 'ng2-ace-editor';
 
import {Component, ViewChild} from '@angular/core';
 
//to use theme eclipse
//with angular-cli add "../node_modules/ace-builds/src-min/ace.js" 
//and "../node_modules/ace-builds/src-min/theme-eclipse.js" to "scripts" var into the file angular-cli.json
 
@Component({
    template: `
  <ace-editor
       [(text)]="text" // possible two way binding (thx ChrisProlls)
        #editor style="height:150px;"></ace-editor>
  `
})
export class AceCmp {
    @ViewChild('editor') 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) {
 
            }
        })
    }
}

Use AOT (thx Geschan)

// other imports
import { AceEditorModule } from 'ng2-ace-editor';
 
@NgModule({
  imports: [
    // ...
    AceEditorModule
  ],
  declarations: [  ],
  providers: [  ]
})
export class AppModule {
}

Used by

caravel.design - example

Dependencies (2)

Dev Dependencies (37)

Package Sidebar

Install

npm i angular-ace-editor

Weekly Downloads

20

Version

0.2.3

License

MIT

Last publish

Collaborators

  • leviathanbadger