editor.js icon indicating copy to clipboard operation
editor.js copied to clipboard

Angular support

Open webpreneur opened this issue 7 years ago • 34 comments

Does the library supports Angular? Are you planning on supporting it in the future?

webpreneur avatar Apr 10 '19 10:04 webpreneur

Hi @webpreneur !

You should be able to use Editor.js in Angular without any problem. However we are planning to create package with Angular component soon

gohabereg avatar Apr 10 '19 10:04 gohabereg

I am also expecting Angular support.!!!

maxn0d3x avatar Apr 10 '19 13:04 maxn0d3x

Would totally love angular support. That would rock! Let me know if you need help.

tekknikk avatar Apr 18 '19 12:04 tekknikk

Oh yes, this would be excellent. I am integrating editorjs into an Ionic project. They have a tool called Stencil that allows you to create web components from Javascript. This would allow it to work with any framework and use native dom elements. Maybe something to look into?

MikeLallemont avatar Apr 22 '19 12:04 MikeLallemont

@gohabereg Thank you for telling us about your plans regarding an angular package. In the meantime I tried to get editor.js running in one of our angular applications. I suppose it's not as easy, as one might think. After importing and constructing the editorjs object I get: Editor.js is not ready because of Error: element with ID «editor-js» is missing. Pass correct holder's ID..

The element with the id editor-js does exist inside the same component. My guess is, that due to angulars encapsulation, the editorjs library can not access the html element to create the editor.

Can you maybe point me to the right direction? Do you happen to have a sample where editorjs is used with angular?

thanks again for the great work :+1:

EDIT: Nevermind. I had the div with editor-js id in a tab, where the html was not rendered on component loading. :man_facepalming:

I am leaving this here for others to explore editorjs with angular:

Install: npm i @editorjs/editorjs

component.ts

import EditorJS from '@editorjs/editorjs';
// ...
ngOnInit() {
      const editor = new EditorJS('editor-js');
}

component.html

<div id="editor-js"></div>

:crossed_fingers:

riscie avatar May 02 '19 19:05 riscie

@webpreneur @gohabereg Hi, so I've been working on this anyway so I've released a open-source library for this:

https://github.com/tanepiper/ngx-tinynodes/tree/master/libs/ngx-editorjs

I'll publish it on NPM with @tinynodes/ngx-editorjs - I've published a 0.0.1 version for now as a placeholder until I can write docs, but have a look in the example app how to import and use it.

https://github.com/tanepiper/ngx-tinynodes/tree/master/apps/ngx-tinynodes/src

Since I'm intending to use this myself in a project I'll be releasing new features soon.

tanepiper avatar May 09 '19 08:05 tanepiper

@gohabereg @webpreneur ~~I've released v1.0.0 on npm~~ I've released 1.1.0 on NPM and written a blog post https://tane.dev/2019/05/ngx-editorjs-library-for-angular/

There is a working demo here: https://tinynodes-ngx.firebaseapp.com/ngx-editorjs-demo

It look me a little longer to release as I had to fix an AOT issue - there's details in the README on how to import EditorJS tools that supports production compiling: https://github.com/tanepiper/ngx-tinynodes/blob/master/libs/ngx-editorjs/README.md

Update: Also now generated docs: https://tanepiper.github.io/ngx-tinynodes/

tanepiper avatar May 10 '19 10:05 tanepiper

I installed this package and it required peer dependencies of @editorjs/editorjs, @editorjs/header, @editorjs/list and @editorjs/paragraph. Then the module NgxEditorJSModule is not located at @tinynodes/ngx-editorjs but at @tinynodes/ngx-editorjs/src.

Maybe fix that or update documentation?

But thanks so much for making this! Looking forward to using it.

Mike

On May 10, 2019, at 5:00 AM, Tane Piper [email protected] wrote:

@gohabereg @webpreneur I've released v1.0.0 on npm.

There is a working demo here: https://tinynodes-ngx.firebaseapp.com/ngx-editorjs-demo

It look me a little longer to release as I had to fix an AOT issue - there's details in the README on how to import EditorJS tools that supports production compiling: https://github.com/tanepiper/ngx-tinynodes/blob/master/libs/ngx-editorjs/README.md

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

MikeLallemont avatar May 11 '19 18:05 MikeLallemont

Hi @MikeLallemont

Thanks for the feedback - I've released 1.2.0 today and now have full docs here: https://tanepiper.github.io/ngx-tinynodes/

In regards to the peer dependencies, this is because Angular AOT requires these dependencies to be at the root of the project, adding them as hard dependencies won't work. I've added added a quick notes here in the plugin docs.

I've also removed default plugins from the core package, you now need to pass them manually within the config for header, paragraph and list. This is mostly due to a @nrwl/nx issue with monorepos, allowing me to release.

If you have any more feedback feel free to leave issues on my main repo

tanepiper avatar May 13 '19 09:05 tanepiper

Tane,

Great work and I appreciate so much. But a few of those links are 404s and it would be super helpful if you had some documentation of what the Angular template should look like or have the source to the demo available. I found some code for he nav-bar, side-menu, etc. but nowhere could I find the main editor demo code. When I load the demo page it does not show the editor anymore either. Maybe something got deleted?

Anyway, I’m looking forward to using it when it all comes together and I’ll add bugs or feature requests as I come across. Are you planning on making the component work as an Angular form control? If so that would be ideal.

Thanks again for the hard work!

Mike

On May 13, 2019, at 4:16 AM, Tane Piper [email protected] wrote:

Hi @MikeLallemont https://github.com/MikeLallemont Thanks for the feedback - I've released 1.2.0 today and now have full docs here: https://tanepiper.github.io/ngx-tinynodes/ https://tanepiper.github.io/ngx-tinynodes/ In regards to the peer dependencies, this is because Angular AOT requires these dependencies to be at the root of the project, adding them as hard dependencies won't work. I've added added a quick notes here https://github.com/tanepiper/ngx-tinynodes/tree/master/libs/ngx-editorjs-plugins in the plugin docs.

I've also removed default plugins from the core package, you now need to pass them manually within the config for header, paragraph and list. This is mostly due to a @nrwl/nx issue with monorepos, allowing me to release.

If you have any more feedback feel free to leave issues on my main repo https://github.com/tanepiper/ngx-tinynodes/issues — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/codex-team/editor.js/issues/716#issuecomment-491743626, or mute the thread https://github.com/notifications/unsubscribe-auth/AAOC4W767ZFYXY5GFNIHFKLPVEWV5ANCNFSM4HE2PFMQ.

MikeLallemont avatar May 14 '19 01:05 MikeLallemont

@MikeLallemont Thanks for the feedback - aware of a few 404's due to the way Compodoc works, I'll look to resolve that soon.

If you look in the docs for the module and demo module:

https://tanepiper.github.io/ngx-tinynodes/modules/NgxEditorJSModule.html https://tanepiper.github.io/ngx-tinynodes/components/NgxEditorJSComponent.html

These have example uses. I'm working on 1.3 just now, but this will mostly be unit tests I'm working on - I'll also possibly have a pre-build form component for reactive and template driven forms, it's on my feature list but I had some issues with the first version I wrote so I need to re-think it slightly.

Also: When I load the demo page it does not show the editor anymore either. Maybe something got deleted?

https://tinynodes-ngx.firebaseapp.com/ngx-editorjs-demo/pages/editor is not loading for you? Do you have an editor but just no block plugins? Please feel free to leave an issue on the repo issues and I can try take a look.

tanepiper avatar May 14 '19 06:05 tanepiper

@MikeLallemont Hello again, I've since released 1.3.2

Have a look at the demo on https://tinynodes-ngx.firebaseapp.com/ngx-editorjs-demo/pages

In regards to using it, have a look at https://tanepiper.github.io/ngx-tinynodes/components/PageContainerComponent.html#info

This version is mostly internal changes, I didn't get time to do the Form component - but now it should be easier, this version was mostly making the EditorJS more accessible in Angular and work with more observable values.

tanepiper avatar May 15 '19 14:05 tanepiper

Hello again issue subscribers! I've just released 2.0.0 and it's quite a big change internally, also now the component works with Angular Forms out the box. Not only that, there is a native Material component to use (see demo).

Docs have been updated quite a bit and again the demo in the repo show's example usage with auto save support

tanepiper avatar May 22 '19 19:05 tanepiper

How to use EditorJs with Angular 9 using ViewChild :

component.html

<div #editorJs></div>

component.ts

import { Component, Input, ViewChild, ElementRef, AfterViewInit } from '@angular/core';
import EditorJS from '@editorjs/editorjs';
import Header from '@editorjs/header'; 
import List from '@editorjs/list'; 

@Component({
  selector: 'app-component',
  templateUrl: './.component.html',
  styleUrls: ['./component.scss']
})
export class Component implements AfterViewInit {
  @ViewChild('editorJs') el:ElementRef;

  constructor() { }

  ngAfterViewInit() {
    const editor = new EditorJS({
      holder: this.el.nativeElement,
      tools: { 
        header: Header, 
        list: List,
      }, 
      
    });
  }

}

leorolland avatar Feb 09 '20 22:02 leorolland

Somehow this code throws me that element is undefined. Did you use some timeout on the original code?

EDIT: Nevermind, managed to get it working when moved my http.get function to ngOnInit() - this way it didnt conflict with your way. Thanks!

Pietrox avatar Feb 24 '20 15:02 Pietrox

When compiling. In Angular 9 gives me the following error.

ERROR in node_modules/@editorjs/editorjs/types/api/block.d.ts:2:25 - error TS2307: Cannot find module '../../src/types-internal/block-data'.

markCornejo avatar Jun 04 '20 01:06 markCornejo

How to use EditorJs with Angular 9 using ViewChild :

component.html

<div #editorJs></div>

component.ts

import { Component, Input, ViewChild, ElementRef, AfterViewInit } from '@angular/core';
import EditorJS from '@editorjs/editorjs';
import Header from '@editorjs/header'; 
import List from '@editorjs/list'; 

@Component({
  selector: 'app-component',
  templateUrl: './.component.html',
  styleUrls: ['./component.scss']
})
export class Component implements AfterViewInit {
  @ViewChild('editorJs') el:ElementRef;

  constructor() { }

  ngAfterViewInit() {
    const editor = new EditorJS({
      holder: this.el.nativeElement,
      tools: { 
        header: Header, 
        list: List,
      }, 
      
    });
  }

}

I'm trying to use editorjs using this method in Angular but when I try to add a block by clicking or by using a shortcut I get the following error, apart from the paragraph block which works ok.

error-handler.service.ts:12 TypeError: Cannot read property 't' of undefined
    at new t (bundle.js:formatted:1)
    at e.value (bundle.js:formatted:1)
    at e.value (bundle.js:formatted:1)
    at e.value (bundle.js:formatted:1)
    at e.value (bundle.js:formatted:1)
    at e.value (bundle.js:formatted:1)
    at HTMLLIElement.<anonymous> (bundle.js:formatted:1)
    at ZoneDelegate.invokeTask (zone-evergreen.js:391)
    at Object.onInvokeTask (bundle.js:formatted:1)
    at ZoneDelegate.invokeTask (zone-evergreen.js:390)

My current config is

 const editor = new EditorJS({
      holder: this.el.nativeElement,
      placeholder: 'Write blog here!',
      tools: {
        header: {
          class: Header,
          shortcut: 'CMD+SHIFT+H',
        },
        list: {
          class: List,
          inlineToolbar: true,
        },
        paragraph: {
          class: Paragraph,
          inlineToolbar: true,
        },
      },
    });

dottodot avatar Jun 11 '20 07:06 dottodot

When compiling. In Angular 9 gives me the following error.

ERROR in node_modules/@editorjs/editorjs/types/api/block.d.ts:2:25 - error TS2307: Cannot find module '../../src/types-internal/block-data'.

Same issue here in Angular 8

susana-bit avatar Jun 16 '20 12:06 susana-bit

I am trying to use Editor.js in one of my Angular apps and when I try to configure heading, lists and other blocks, it gives me the following error:

ERROR TypeError: Cannot read property 't' of undefined
    at e.value (bundle.js:10)
    at new e (bundle.js:10)
    at e.value (editor.js:2)
    at e.value (editor.js:2)
    at e.value (editor.js:2)
    at e.value (editor.js:2)
    at e.value (editor.js:2)
    at HTMLLIElement.<anonymous> (editor.js:2)
    at ZoneDelegate.invokeTask (zone-evergreen.js:391)
    at Object.onInvokeTask (core.js:39680)

This is the code snippet of my component.

import { Component, OnInit } from '@angular/core';
import EditorJS from '@editorjs/editorjs';
import Header from '@editorjs/header';
import List from '@editorjs/list';

@Component({
  selector: 'app-editorjs',
  templateUrl: './editorjs.component.html',
  styleUrls: ['./editorjs.component.css']
})
export class EditorjsComponent implements OnInit {

  editor;

  constructor() { }

  ngOnInit() {
    this.editor = new EditorJS({
      holder: 'editor-js',
      tools: {
        header: {
          class: Header,
          shortcut: 'CMD+SHIFT+H',
        },
        list: {
          class: List,
          inlineToolbar: true,
        },
      }
    });
  }

  onSave() {
    this.editor.save().then((outputData) => {
      console.log('Article data: ', outputData)
    }).catch((error) => {
      console.log('Saving failed: ', error)
    });
  }
}

Anybody knows how to fix this? :(

EDIT

https://stackblitz.com/edit/angular-ivy-ypbuje

khan9920 avatar Jun 17 '20 11:06 khan9920

@khan9920 I had this problem too. It seems to be resolve in the latest version but you will get a type error when trying to build using it. So I use patch-package to resolve the type error.

dottodot avatar Jun 17 '20 17:06 dottodot