GrapesJS / grapesjs

Free and Open source Web Builder Framework. Next generation tool for building templates without coding
https://grapesjs.com
BSD 3-Clause "New" or "Revised" License
22.14k stars 4.02k forks source link

Rendering Angular components in GrapesJS. #3074

Closed suryalijo closed 3 years ago

suryalijo commented 3 years ago

Rendering Angular components in GrapesJS.

I am creating an Angular editor with GrapesJS. I am able to integrate GrapesJS in my Angular project and I also created custom components and blocks that can be used to build tools. Is there a way to render Angular components directly into Grapes JS editor?

artf commented 3 years ago

Not really, you have to create a custom renderer for your components (similar issue but for React #1970). There is also https://github.com/artf/grapesjs-mjml plugin which uses a similar approach to render components from another framework

suryalijo commented 3 years ago

Thanks, I was able to render angular components in gjs by using createCustomElement. image

vijaycreatise commented 3 years ago

Thanks, I was able to render angular components in gjs by using createCustomElement. image

@suryalijo Can you please tell me the process how to did you do that? I'm also looking for the same solution.

suryavijayakumar1315 commented 3 years ago

Add AngularComponent as entryComponents in the app module, then import createCustomElement like given below

import { createCustomElement } from '@angular/elements';
export class AppComponent {
  constructor( injector: Injector ) {
    customElements.define('popup-element', createCustomElement(AngularComponent, {injector}));
}

Now use "popup-element" in grapesjs

vijaycreatise commented 3 years ago

@suryavijayakumar1315 thank you will try this.

Guruk13 commented 3 years ago

@suryavijayakumar1315

Now use "popup-element" in grapesjs

Hi , can you give some hints on this step ? I've managed to turn a simple Ng Component into a custom element that the browser can interpret in a component.html file , namely <mycustomelement></mycustomelement> But how do you bundle that into grapejs ? i've tried blocks with the tag above but ng is'nt wiring correctly ...

have you used blockManager ? gjs CustomComponents ? gjs ComponentTypes ? Many Thanks PS: #2506 is related to this

suryavijayakumar1315 commented 3 years ago

I am using the custom element like this in Block Manager

this.editor.BlockManager.add('block_name' , { label: 'label', type: 'type', content: <div><mycustomelement></mycustomelement></div> category: 'category_name' });

Guruk13 commented 3 years ago

Thanks, My app has a router with eager loading so i guess i should study injectors behaviour Cheers

FaziHamza commented 9 months ago

how to add our angular 14 component in grapesjs with style etc.