1

Is there a way to get component css from the Backend configuration? like liferay

I have a component and this component provides textbox for the user to enter css code. Whatever css user enters in the texbox should reflect in component.

component html

<div>
<h1>I am h1 tag<h1>
<h2>I am h2 tag<h2>
<div>

Editor enter image description here

Output

enter image description here

Editor

enter image description here

Output

enter image description here

1 Answer 1

1

No one answered so answering my own question. Actually this is very simple. Just create a style tag and apply css

<div id="dynamicStyle">
<h1>I am h1 tag<h1>
<h2>I am h2 tag<h2>
<div>

component

export class SomeComponent implements OnInit {
  color = 'red';
  ngOnInit() {
    const css = `h2 {color: green} img {background: ${this.color}`; // we can get this css from backend also
    const head = document.getElementById('dynamicStyle');
    const style = document.createElement('style');
    style.type = 'text/css';
    style.appendChild(document.createTextNode(css));
    head.appendChild(style);
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.