Demo
Angular Froala WYSIWYG Editor -Angular 2 and Angular 4 bindings for Froala WYSIWYG Editor.
Table of contents
- Installation instructions
- Update editor instructions
- Integration
- Usage
- Manual Initialization
- Displaying HTML
- License
- Development environment setup
Installation instructions
Install angular-froala-wysiwyg
from npm
npm install angular-froala-wysiwyg
You will need CSS styles and Font Awesome
<!-- index.html -->
Update editor instructions
npm update froala-editor --save
Integration
Use with Angular CLI
Installing @angular/cli
Note: you can skip this part if you already have application generated.
npm install -g @angular/cling new my-appcd my-app
Add angular-froala-wysiwyg
- install
angular-froala-wysiwyg
npm install angular-froala-wysiwyg --save
- open
src/app/app.module.ts
and add
// Import Angular plugin.;...
- open
.angular-cli.json
file and insert a new entry into thestyles
array
"styles":
- in .
angular-cli.json
file insert a new entry into thescripts
array
"scripts":
- open
src/app/app.component.html
and add
Hello, Froala!
Run angular-cli
ng serve
ionic v2 or v3
Use with Create Ionic app
Note: you can skip this part if you already have application generated.
npm install -g cordova ionicionic start myApp blankcd myApp
Add angular-froala-wysiwyg
For v3 make sure that you use the latest version of ionic and also the latest version of angular.
Installing Froala Wysiwyg Editor in Ionic is fairly easy, it can be done using npm:
npm install angular-froala-wysiwyg --save
- open
src/app/app.module.ts
and add
// Import Froala Editor.; // Import Angular2 plugin.;...
- open
src/app/main.ts
and add
;window"$" = $;window"jQuery" = $;
- In
package.json
add the following:
"config":
- Run the following commands
mkdir configcp node_modules/@ionic/app-scripts/config/copy.config.js ./config/
- Open
config/copy.config.js
file and add the following at the beginning ofmodule.exports
moduleexports = copyFroalaEditorCss: src: '{{ROOT}}/node_modules/froala-editor/css/froala_editor.pkgd.min.css' '{{ROOT}}/node_modules/froala-editor/css/froala_style.min.css' dest: '{{BUILD}}' copyFontAwesome: src: '{{ROOT}}/node_modules/font-awesome/css/font-awesome.min.css' dest: '{{BUILD}}' copyFontsAwesomeFonts: src: '{{ROOT}}/node_modules/font-awesome/fonts/*' dest: '{{WWW}}/fonts' ...
- Open
src/index.html
file and add in the<head>
tag:
In your desired view add the Froala Editor like this:
Hello, Froala!
Run your App
ionic serve
webpack
Use with Create webpack app
Note: you can skip this part if you already have application generated.
git clone --depth 1 https://github.com/AngularClass/angular-starter.gitcd angular-starternpm install
Add angular-froala-wysiwyg
- install
angular-froala-wysiwyg
npm install angular-froala-wysiwyg --save
- open
src/app/app.module.ts
and add
// Import the Froala Editor plugin.; // Import Angular plugin.;...
- open
src/app/app.component.ts
and add to the template
Hello, Froala!
- open
config/webpack.common.js
and add the following toCopyWebpackPlugin
from: 'node_modules/froala-editor/css/' to: 'assets/froala-editor/css/' from: 'node_modules/font-awesome/css/font-awesome.min.css' to: 'assets/font-awesome/css/font-awesome.min.css' from: 'node_modules/font-awesome/fonts' to: 'assets/font-awesome/fonts'
- in
config/webpack.common.js
copy the following toplugins
$: "jquery" jQuery: "jquery"
- open
config/head-config.common.js
and add a new entry to link
rel: 'stylesheet' href: '/assets/font-awesome/css/font-awesome.min.css' rel: 'stylesheet' href: '/assets/froala-editor/css/froala_editor.pkgd.min.css' rel: 'stylesheet' href: '/assets/froala-editor/css/froala_style.min.css'
Run webpack app
npm run start
angular-seed
Use with Create angular-seed app
Note: you can skip this part if you already have application generated. For more details please also read: https://github.com/mgechev/angular-seed.
git clone --depth 1 https://github.com/mgechev/angular-seed.gitcd angular-seednpm install
Add angular-froala-wysiwyg
- install
angular-froala-wysiwyg
npm install angular-froala-wysiwyg --save
- open
tools/config/project.config.ts
file and uncomment the following line from the top of the file
;
- in
tools/config/project.config.ts
file add
... this.NPM_DEPENDENCIES = ; ... this.addPackagesBundlesadditionalPackages;
- open
src/client/app/home/home.module.ts
and add
// Import Angular2 plugin.;...
- open
src/client/app/home/home.component.html
and add
Hello, Froala!
Run webpack app
npm run start
system.js
and JIT
Use with Create Angular app
Note: you can skip this part if you already have application generated.
git clone https://github.com/angular/quickstart.git angular-quickstartcd angular-quickstartnpm install
Add angular-froala-wysiwyg
- install
angular-froala-wysiwyg
npm install angular-froala-wysiwyg --save
- open
src/index.html
and add
- open
src/app/app.module.ts
and add
// Import Angular2 plugin.;...
- open
src/app/app.component.ts
file and add to the template
Hello, Froala!
- open
src/systemjs.config.js
file and add to map
map: ... 'angular-froala-wysiwyg': 'npm:angular-froala-wysiwyg/bundles/angular-froala-wysiwyg.umd.js' ...
Hello, Froala!
-
Run app
npm run start
aot
Use with Create Angular app
Note: you can skip this part if you already have application generated.
git clone https://github.com/angular/quickstart.git angular-quickstartcd angular-quickstartnpm install
Install additional dependencies. Make sure that there is no UNMET PEER DEPENDENCY.
npm install @angular/compiler-cli @angular/platform-server --savenpm install rollup rollup-plugin-node-resolve rollup-plugin-commonjs rollup-plugin-uglify --save-devnpm install lite-server --save-dev
Copy scr/tsconfig.json
to a new file called tsconfig-aot.json
in the root of the project, then modify it as follows.
Create a configuration file (rollup-config.js
) in the project root directory to tell Rollup how to process the application.
;;; entry: 'src/main.js' dest: 'src/build.js' // output a single application bundle sourceMap: false format: 'iife' { // Skip certain warnings // should intercept ... but doesn't in some rollup versions if warningcode === 'THIS_IS_UNDEFINED' return; // console.warn everything else console; } plugins: ;
Update src/main.ts
file for AOT:
;; console.log'Running AOT compiled';platformBrowser.bootstrapModuleFactoryAppModuleNgFactory;
Add angular-froala-wysiwyg
- install
angular-froala-wysiwyg
npm install angular-froala-wysiwyg --save
- open
src/index.html
and add
- open
src/app/app.module.ts
and add
// Import Angular2 plugin.;...
- open
src/app/app.component.ts
file and add to the template
Hello, Froala!
- open
rollup-config.js
and add the following
//paths are relative to the execution path ... plugins: ... ...
Run app
node_modules/.bin/ngc -p tsconfig-aot.jsonnode_modules/.bin/rollup -c rollup-config.js -c rollup-config.jslite-server
Usage
Options
You can pass editor options as Input (optional).
[froalaEditor]='options'
You can pass any existing Froala option. Consult the Froala documentation to view the list of all the available options:
public options: Object =
Aditional option is used:
- immediateAngularModelUpdate: (default: false) This option synchronizes the angular model as soon as a key is released in the editor. Note that it may affect performances.
Events and Methods
Events can be passed in with the options, with a key events and object where the key is the event name and the value is the callback function.
public options: Object =
Using the editor instance from the arguments of the callback you can call editor methods as described in the method docs.
Froala events are described in the events docs.
Model
The WYSIWYG HTML editor content model.
[(froalaModel)]="editorContent"
Pass initial content:
public editorContent: string = 'My Document\'s Title'
Use the content in other places:
<!-- For two way binding -->
Other two way binding example:
Use it with reactive forms:
Submit
If you want to use two-way binding to display de form model in other places you must include [(froalaModel)]
:
Submit
If you want to wrap froalaEditor directive into a component that supports reactive forms please see froala.component.ts from demo.
Extend functionality
You can extend the functionality by adding a custom button like bellow:
// We will make usage of the Init hook and make the implementation there.;declare ;
Special tags
You can also use the editor on img, button, input and a tags:
The model must be an object containing the attributes for your special tags. Example:
public imgObj: Object =;
The froalaModel will change as the attributes change during usage.
- froalaModel can contain a special attribute named innerHTML which inserts innerHTML in the element: If you are using 'button' tag, you can specify the button text like this:
public buttonModel: Object =;
As the button text is modified by the editor, the innerHTML attribute from buttonModel model will be modified too.
Specific option for special tags
- angularIgnoreAttrs: (default: null) This option is an array of attributes that you want to ignore when the editor updates the froalaModel:
public inputOptions: Object =;
Manual Initialization
Gets the functionality to operate on the editor: create, destroy and get editor instance. Use it if you want to manually initialize the editor.
(froalaInit)="initialize($event)"
Where initialize
is the name of a function in your component which will receive an object with different methods to control the editor initialization process.
public initializeinitControls
The object received by the function will contain the following methods:
- initialize: Call this method to initialize the Froala Editor
- destroy: Call this method to destroy the Froala Editor
- getEditor: Call this method to retrieve the editor that was created. This method will return null if the editor was not yet created
Displaying HTML
To display content created with the froala editor use the froalaView directive.
[froalaView]="editorContent"
License
The angular-froala-wyswiyg
project is under MIT license. However, in order to use Froala WYSIWYG HTML Editor plugin you should purchase a license for it.
Froala Editor has 3 different licenses for commercial use. For details please see License Agreement.
Development environment setup
If you want to contribute to angular-froala-wyswiyg, you will first need to install the required tools to get the project going.
Prerequisites
- Node Package Manager (NPM)
- Git
Install dependencies
$ npm install
Build
$ npm run demo.build
Run Demo
$ npm run start