Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
angular2-froala-wysiwyg
Advanced tools
Angular2 bindings for Froala WYSIWYG HTML rich text editor
angular2-froala-wyswiyg provides Angular2 bindings to the Froala WYSIWYG editor.
Install angular2-froala-wysiwyg
from npm
npm install angular2-froala-wysiwyg --save
You will need CSS styles and Font Awesome
<!-- index.html -->
<link href="node_modules/froala-editor/css/froala_editor.pkgd.min.css" rel="stylesheet">
<link href="node_modules/font-awesome/css/font-awesome.min.css" rel="stylesheet">
angular-cli
Important: please check angular-cli
version, it should be => "1.0.0-beta.24".
Note: you can skip this part if you already have application generated by ng-cli
and webpack.
npm i -g angular-cli
ng new my-app
cd my-app
angular2-froala-wysiwyg
npm install angular2-froala-wysiwyg --save
src/app/app.module.ts
and add# Import Angular2 plugin.
import { FroalaEditorModule, FroalaViewModule } from 'angular2-froala-wysiwyg';
...
@NgModule({
...
imports: [FroalaEditorModule.forRoot(), FroalaViewModule.forRoot() ... ],
...
})
angular-cli.json
and insert a new entry into the styles
array"styles": [
"styles.css",
"../node_modules/font-awesome/css/font-awesome.css",
"../node_modules/froala-editor/css/froala_editor.pkgd.min.css"
],
angular-cli.json
and insert a new entry into the scripts
array"scripts": [
"../node_modules/jquery/dist/jquery.min.js",
"../node_modules/froala-editor/js/froala_editor.pkgd.min.js"
],
angular-cli.json
add the following to load Font Awesome fonts"addons": [
"../node_modules/font-awesome/fonts/*.+(otf|eot|svg|ttf|woff|woff2)"
],
src/app/app.component.html
and add<div [froalaEditor]>Hello, Froala!</div>
ng serve
ionic v2
Installing Froala Wysiwyg Editor in Ionic is fairly easy, it can be done using npm:
npm install angular2-froala-wysiwyg --save
src/app/app.module.ts
and add# Import Froala Editor.
import "froala-editor/js/froala_editor.pkgd.min.js";
# Import Angular2 plugin.
import { FroalaEditorModule, FroalaViewModule } from 'angular2-froala-wysiwyg';
...
@NgModule({
...
imports: [FroalaEditorModule.forRoot(), FroalaViewModule.forRoot() ... ],
...
})
src/app/main.ts
and addimport * as $ from 'jquery';
window["$"] = $;
window["jQuery"] = $;
This install will come with Font Awesome as a dependency so there are needed a few more steps to finish the install.
"config": {
"ionic_copy": "./config/copy.config.js",
"ionic_sass": "./config/sass.config.js"
}
On the root of your project you need to create a new folder called config and place inside 2 files:copy.config.js & sass.config.js". These files can be copied to new config folder from node_modules/@ionic/app-scripts/config/{{name_of_file}}.js
Modify the copied files. In sass.config.js add the reference to font-awesome, verify that you have something similar to this:
/**
* includePaths: Used by node-sass for additional
* paths to search for sass imports by just name.
*/
includePaths: [
'node_modules/ionic-angular/themes',
'node_modules/ionicons/dist/scss',
'node_modules/ionic-angular/fonts',
'node_modules/font-awesome/scss' // <------ Newly added.
],
In copy.config add this before copyAssets
property:
copyFroalaEditorCss: {
src: '{{ROOT}}/node_modules/froala-editor/css/froala_editor.pkgd.min.css',
dest: '{{SRC}}/assets/'
},
copyFontAwesome: {
src: '{{ROOT}}/node_modules/font-awesome/css/font-awesome.min.css',
dest: '{{SRC}}/assets/'
},
copyFontsAwesomeFonts: {
src: 'node_modules/font-awesome/fonts/*',
dest: '{{WWW}}/fonts/'
},
copyAssets: { //<-------- this should be last.
src: ['{{SRC}}/assets/**/*'],
dest: '{{WWW}}/assets'
}
You should have the files in your {{ROOT}} and {{WWW}} folders ready for further development.
src/theme/variables.css
:,
@import "font-awesome";
Refrence the new scripts on your view html file and everything should work fine.
<link rel="stylesheet" href="/assets/font-awesome.min.css">
<link rel="stylesheet" href="/assets/froala_editor.pkgd.min.css">
In your desired view add the Froala Editor like this:
<div [froalaEditor]>Hello, Froala!</div>
webpack
Note: you can skip this part if you already have application generated.
git clone --depth 1 https://github.com/angularclass/angular2-webpack-starter.git
cd angular2-webpack-starter
npm install
angular2-froala-wysiwyg
npm install angular2-froala-wysiwyg --save
src/app/app.module.ts
and add# Import the Froala Editor plugin.
import "froala-editor/js/froala_editor.pkgd.min.js";
# Import Angular2 plugin.
import { FroalaEditorModule, FroalaViewModule } from 'angular2-froala-wysiwyg';
...
@NgModule({
...
imports: [FroalaEditorModule.forRoot(), FroalaViewModule.forRoot(), ... ],
...
})
src/app/app.component.ts
and add to the template<div [froalaEditor]>Hello, Froala!</div>
config/webpack.common.js
and add the following to CopyWebpackPlugin
{
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'
}
config/webpack.common.js
copy the following to plugins
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery"
})
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' }
npm run start
angular-seed
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.git
cd angular-seed
npm install
angular2-froala-wysiwyg
npm install angular2-froala-wysiwyg --save
tools/config/projesct.config.ts
and uncomment the following line from the top of the fileimport { ExtendPackages } from './seed.config.interfaces';
tools/config/projesct.config.ts
add...
this.NPM_DEPENDENCIES = [
...this.NPM_DEPENDENCIES,
{ src: 'jquery/dist/jquery.min.js', inject: 'libs'},
{ src: 'froala-editor/js/froala_editor.pkgd.min.js', inject: 'libs' },
{ src: 'font-awesome/css/font-awesome.min.css', inject: true },
{ src: 'froala-editor/css/froala_editor.pkgd.min.css', inject: true }
];
...
let additionalPackages: ExtendPackages[] = [
// required for dev build
{
name:'angular2-froala-wysiwyg',
path:'node_modules/angular2-froala-wysiwyg/bundles/angular2-froala-wysiwyg.umd.min.js'
},
// required for prod build
{
name:'angular2-froala-wysiwyg/*',
path:'node_modules/angular2-froala-wysiwyg/bundles/angular2-froala-wysiwyg.umd.min.js'
}
]
this.addPackagesBundles(additionalPackages);
src/client/app/home/home.module.ts
and add# Import Angular2 plugin.
import { FroalaEditorModule, FroalaViewModule } from 'angular2-froala-wysiwyg';
...
@NgModule({
...
imports: [FroalaEditorModule.forRoot(), FroalaViewModule.forRoot() ... ],
...
})
src/client/app/home/home.component.html
and add<div [froalaEditor]>Hello, Froala!</div>
npm run start
system.js
, jit
and aot
Note: you can skip this part if you already have application generated.
git clone https://github.com/angular/quickstart.git quickstart
cd quickstart
npm install
For AOT configuration, please follow the detailed guides from Angular: https://angular.io/docs/ts/latest/cookbook/aot-compiler.html.
angular2-froala-wysiwyg
npm install angular2-froala-wysiwyg --save
src/index.html
and add<link rel="stylesheet" href="node_modules/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="node_modules/froala-editor/css/froala_editor.pkgd.min.css">
<script src="node_modules/jquery/dist/jquery.min.js"></script>
<script src="node_modules/froala-editor/js/froala_editor.pkgd.min.js"></script>
src/app/app.module.ts
and add# Import Angular2 plugin.
import { FroalaEditorModule, FroalaViewModule } from 'angular2-froala-wysiwyg';
...
@NgModule({
...
imports: [FroalaEditorModule.forRoot(), FroalaViewModule.forRoot(), ... ],
...
})
src/app/app.component.ts
and add to the template<div [froalaEditor]>Hello, Froala!</div>
rollup-config.js
and add the following//paths are relative to the execution path
export default {
...
plugins: [
...
commonjs({
include: [
'node_modules/rxjs/**',
'node_modules/angular2-froala-wysiwyg/**'
]
}),
...
]
}
ngc -p tsconfig-aot.json && rollup -c rollup-config.js
npm run start
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 = {
placeholderText: 'Edit Your Content Here!',
charCounterCount: false
}
Aditional option is used:
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 = {
placeholder: "Edit Me",
events : {
'froalaEditor.focus' : function(e, editor) {
console.log(editor.selection.get());
}
}
}
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.
The WYSIWYG HTML editor content model.
[(froalaModel)]="editorContent"
Pass initial content:
public editorContent: string = 'My Document\'s Title'
Use the content in other places:
<input [ngModel]="editorContent"/>
<input [(ngModel)]="editorContent"/> <!-- For two way binding -->
Other two way binding example:
<div [froalaEditor] [(froalaModel)]="editorContent"></div>
<div [froalaEditor] [(froalaModel)]="editorContent"></div>
Use it with reactive forms:
<form [formGroup]="form" (ngSubmit)="onSubmit()">
<textarea [froalaEditor] formControlName="formModel"></textarea>
<button type="submit">Submit</button>
</form>
If you want to use two-way binding to display de form model in other places you must include [(froalaModel)]
:
<form [formGroup]="form" (ngSubmit)="onSubmit()">
<textarea [froalaEditor] formControlName="formModel" [(froalaModel)]="form.formModel"></textarea>
<div [froalaView]="form.formModel"></div>
<button type="submit">Submit</button>
</form>
If you want to wrap froalaEditor directive into a component that supports reactive forms please see froala.component.ts from demo.
You can also use the editor on img, button, input and a tags:
<img [froalaEditor] [(froalaModel)]="imgObj"/>
The model must be an object containing the attributes for your special tags. Example:
public imgObj: Object = {
src: 'path/to/image.jpg'
};
The froalaModel will change as the attributes change during usage.
public buttonModel: Object = {
innerHTML: 'Click Me'
};
As the button text is modified by the editor, the innerHTML attribute from buttonModel model will be modified too.
public inputOptions: Object = {
angularIgnoreAttrs: ['class', 'id']
};
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 initialize(initControls) {
this.initControls = initControls;
this.deleteAll = function() {
this.initControls.getEditor()('html.set', '');
};
}
The object received by the function will contain the following methods:
To display content created with the froala editor use the froalaView directive.
[froalaView]="editorContent"
<div [froalaEditor] [(froalaModel)]="editorContent"></div>
<div [froalaView]="editorContent"></div>
The angular2-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.
If you want to contribute to angular2-froala-wyswiyg, you will first need to install the required tools to get the project going.
$ npm install
$ npm run demo.build
$ npm run start
FAQs
Angular2 bindings for Froala WYSIWYG HTML rich text editor
The npm package angular2-froala-wysiwyg receives a total of 26 weekly downloads. As such, angular2-froala-wysiwyg popularity was classified as not popular.
We found that angular2-froala-wysiwyg demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.