Code Monkey home page Code Monkey logo

ng2-froala-editor's Introduction

Angular Component for Froala Editor

This is Angular2 component for Froala Editor. This allows developers to easily integrate this powerful WYSIWYG editor into any applications. Most of the method calls, set up events listening, and options for the editors are still the same and follow the documentation of Froala Editor.
In order to use this component, you would need to include all the font-awesome css, jQuery and Froala js and css files in index.html Please feel free to make suggestions if you have ideas to improve it.
All development for this project sponsored by Thrinacia, The Next Generation CrowdFunding Infrastructure - https://www.thrinacia.com.

Demo

(Some links here to show how it works)

Quick Start

npm install ng2-froala-editor --save

Angular 4 Version

The most recent version of this module (1.0.17) uses Angular 4.0.0
If you have encountered problem, you may use the previous version (1.0.15), which was based on Angular 2.0.0

Example

In your NgModule:

import {NgModule} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {FormsModule} from '@angular/forms';
import {FroalaEditorModule} from 'ng2-froala-editor/ng2-froala-editor'; // <-- Import it in your NgModule
import {HttpModule} from '@angular/http';
import {MyComponent} from './My.component';
import {MyService} from './My.service';

@NgModule({
  imports: [
    BrowserModule,
    FormsModule,
    FroalaEditorModule  // <-- Include in your module
  ],
  declarations: [
    MyComponent
  ],
  bootstrap: [
    MyComponent
  ],
  providers: [
    MyService
  ]
})

export class AppModule { }

In your component:

import {Component, OnInit} from '@angular/core';
import {FroalaEditorComponent} from 'ng2-froala-editor/ng2-froala-editor';    <-- add this to get instance of FroalaEditorComponent

@Component({
  selector: 'my-component',
  template: `
    <froala [froalaOptions]="froalaOptions" [froalaData]="text" (model)="onFroalaModelChanged($event)" (editorInitialized)="onEditorInitialized()"></froala>
  `
})

export class MyComponent implements OnInit {

  text = '<div>Hey we are testing Froala Editor</div>';
  editor: any;

  froalaOptions: any = {
    height: 300
  };

  constructor() {

  }

  ngOnInit() {

  }

  onFroalaModelChanged(event: any) {
    setTimeout(() => {
      this.text = event;
    });
  }

  onEditorInitialized(event?: any) {
    this.editor = FroalaEditorComponent.getFroalaInstance();
    this.editor.on('froalaEditor.focus', (e, editor) => {
      console.log("editor is focused");
    });
  }
}

Docs

Inputs

  • froalaData [string] If you have strings you would like the editor to have when it initializes, you can put it here
  • froalaOptions [object] When Froala Editor initializes, you can pass an object to the editor to use different options. For the list of options, you can see it on Froala options

Outputs

  • model [Event]
  • editorInitialized [Event] This emits an event without any data. You can catch it if your component needs to know when the editor finishes initializing. One of the use cases is to get the Froala Editor instance

Static Method

  • getFroalaInstance() Returns a Froala Editor instance, or the DOM the editor resides. From there you can call Froala's method and set up listener for events

Froala

Here is a snippet of how you can interact with the editor. Use onEditorInitialized() function above as example:

onEditorInitialized(event?: any) {
  // Save the editor instance
  this.editor = FroalaEditorComponent.getFroalaInstance();

  // Listen to Froala Editor's event
  this.editor.on('froalaEditor.focus', (e, editor) => {
    console.log("editor is focused");

    // Use Froala Editor's method
    this.editor.froalaEditor('codeView.toggle');
  });

}

ng2-froala-editor's People

Contributors

ericleethrinacia avatar madankapoor avatar stardustxx avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.