Comments (10)
In case this helps anyone else, here is a version of @xdan's implementation, but with working ngModel
functionality.
import {
Component,
Provider,
OnDestroy,
AfterViewInit,
Input,
forwardRef
} from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
const CUSTOM_INPUT_CONTROL_VALUE_ACCESSOR: Provider = {
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => SimpleJoditComponent),
multi: true
};
@Component({
selector: 'simple-jodit',
template: `<textarea id="{{elementId}}" (change)="onChange($event)" (blur)="onBlur()"></textarea>`,
styleUrls: ['./simple-jodit.component.css'],
providers: [CUSTOM_INPUT_CONTROL_VALUE_ACCESSOR]
})
export class SimpleJoditComponent implements AfterViewInit, OnDestroy, ControlValueAccessor {
@Input() elementId: String;
editor;
private _value = '';
private onTouchedCallback: () => {};
private onChangeCallback: (_: any) => {};
get value(): any {
if (this.editor) {
return this.editor.getEditorValue();
} else {
return null;
}
}
set value(v: any) {
if (this.editor) {
this.editor.setEditorValue(v || '');
}
}
onBlur() {
this.onTouchedCallback();
}
ngAfterViewInit() {
this.editor = new Jodit('#' + this.elementId, {});
}
ngOnDestroy() {
this.editor.destruct();
}
onChange(event: any) {
this.onChangeCallback(event.target.value);
}
writeValue(v: any): void {
this.value = v;
}
registerOnChange(fn: any): void {
this.onChangeCallback = fn;
}
registerOnTouched(fn: any): void {
this.onTouchedCallback = fn;
}
setDisabledState?(isDisabled: boolean): void {
// TODO: see if Jodit has built is disabled state
}
}
And from the parent component...
<simple-jodit #editor [elementId]="'editor'" [(ngModel)]="someProperty"></simple-jodit>
from jodit.
Hi, based on your code - i wrote component
https://xdsoft.net/jodit/examples/intergration/angular-jodit.html
from jodit.
I try to create angular module, but now you can use it like this
in your angular-cli.json
"scripts": [
"../node_modules/jodit/build/jodit.min.js",
],
in typings.d.ts
add
declare var jodit: any;
and create component like this
import {
Component,
OnDestroy,
AfterViewInit,
EventEmitter,
Input,
Output
} from '@angular/core';
@Component({
selector: 'simple-jodit',
template: `<textarea id="{{elementId}}"></textarea>`
})
export class SimpleJoditComponent implements AfterViewInit, OnDestroy {
@Input() elementId: String;
@Output() onEditorKeyup = new EventEmitter<any>();
editor;
ngAfterViewInit() {
this.editor = new Jodit('#' + this.elementId, {});
}
ngOnDestroy() {
this.editor.destruct();
}
}
and use it
<simple-jodit
[elementId]="'my-editor-id'"
(onEditorKeyup)="keyupHandlerFunction($event)"
>
</simple-jodit>
from jodit.
I can see that the src/ has Jodit.ts that exports Jodit, but I can't find a way to import it successfully.
from jodit.
Are you using TypeScript? Show me your code please
from jodit.
I am. I am using Ionic 3 which is based on Angular 5. I've tried both of these methods for importing Jodit:
import * as Jodit from 'jodit/src';
which gives me a lot of errors like:
typescript: node_modules/jodit/src/Config.ts, line: 523 Cannot find name 'require'.
and
import { Jodit } from 'jodit';
which gives me:
Error: Uncaught (in promise): Error: Cannot find module "jodit" Error: Cannot find module "jodit"
from jodit.
Here's a link to the github:
https://github.com/tonymccallie/jupiter/blob/master/src/pages/page-create/page-create.ts
from jodit.
Thanks so much for your reply. I was able to take what you gave me and make it work. I'm using Ionic's Lazy Loading of pages, which made some complications, but here's the solution I found (in case it will help someone else)
in package.json you need to add the section:
"config": {
"ionic_copy":"./copy.config.js"
},
in the same folder as package.json you need a file copy.config.js
with these contents
module.exports = {
copyJodit: {
src: '{{ROOT}}/node_modules/jodit/build/jodit.min.js',
dest: '{{BUILD}}'
},
copyJoditCss: {
src: '{{ROOT}}/node_modules/jodit/build/jodit.min.css',
dest: '{{BUILD}}'
}
}
in my index.html, I had to add the following lines:
<link href="build/jodit.min.css" rel="stylesheet"><!-- after main.css -->
...
<script src="build/jodit.min.js"></script><!-- before main.js -->
I created a component with ionic g component Jodit
and included the Component Code you gave above, PLUS, I added the declaration there
declare var Jodit: any;
on the page I wanted the editor, I had to include the shared components module in the page.module.ts file
import { ComponentsModule } from './../../components/components.module';
...
imports: [
IonicPageModule.forChild(TestPage),
ComponentsModule
],
That allowed me to use the other code like you specified in the previous post.
Thanks for an awesome editor and your responses.
from jodit.
@xdan Not using Ionic, but your solution still worked for me. I did have to capitalize the Jodit
var in typings.d.ts
, but besides that, running ng generate component somepath/simple-jodit
, overwriting the generated simple-jodit.component.ts
with your version and deleting the unneeded simple-jodit.component.html
seems to have everything in clean, working order.
Though this is a good stopgap, do you plan on implementing official Angular support in the future? I would love to help in the effort, but I think my newness to both Angular 2+ and TypeScript would be more of a hindrance than a help.
from jodit.
@xdan Hello, I'm using Ionic 3, Angular 4 and typescript 2.3.4.
Using the wrapper component angular-jodit, I get those 2 errors:
[09:27:03] transpile started ...
[09:27:10] typescript: node_modules/jodit-angular/Events.d.ts, line: 6
Cannot find name 'Jodit'.
L5: args: any[];
L6: editor: Jodit;
[09:27:10] typescript: node_modules/jodit-angular/jodit-angular.component.d.ts, line: 13
Cannot find name 'Jodit'.
L12: element: HTMLElement;
L13: editor: Jodit;
L14: constructor(elementRef: ElementRef, ngZone: NgZone);
Any idea? Thanks.
from jodit.
Related Issues (20)
- Upload images aspect ratio changes when view them in mobile or tablet screen.
- Jodit editor doesn't auto resize youtube insert at phone screen sizes. HOT 1
- Jodit not hiding the raw textarea HOT 6
- Add Handlebars support
- Get file name of drag & drop element (base64)
- How to add inline styles to bold fonts HOT 2
- FileBrowser - Multiple Sources HOT 1
- Editor inserts plain html/xml without linebreaks "paste Insert as Text" or removes everything and only keeps text "paste -> keep" HOT 3
- FileBrowser Upload Button Not Disabled Based on Permissions HOT 1
- FileBrowser - Permissions Incorrect during Open of Dialog
- Maintained? HOT 7
- Selection by triple click removes close tag + open tag of next paragraph
- Handling beforeGetValueFromEditor in Jodit-React? HOT 1
- Wrong generation of es5 bundle - polyfills missing
- Size of picture is not correct when changin a picture
- Popups in plugins like resizer and image-properties which should open popups do not work when in a Shadow DOM in LIT HOT 2
- Paragraph configuration not work as expected and shows more options than configration defined in the config file HOT 1
- Disabling the color plugin does not disable it for table cells
- no build folder/please provide final js and css HOT 4
- OEM version lineheight HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jodit.