Set HTML with style in a GrapesJs component

134 views Asked by At

I use GrapesJs and I want to update the html content of a component.
So I use the components method of a component : cmp.components('<h1 style="text-align:left">Hello</h1>').
But when I retrieve the html content of my component (cmp.toHTML()) the style is not here.

2

There are 2 answers

0
K.Vu On BEST ANSWER

It was an issue with my grapesjs version. I was in 0.21.1 and the problem disappears using 0.21.5.

0
AL Faiz Ahmed On

You can replace cmp.components(...) with below code

cmp.addComponent({
  tagName: 'h1',
  content: 'Hello', // Text inside component
  style: { text-align: 'right'},
});