angular2从后端配置获取组件css [英] angular2 get component css from backend configuration
本文介绍了angular2从后端配置获取组件css的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有从后端配置中获取组件CSS的方法?就像liferay
Is there a way to get component css from the Backend configuration? like liferay
我有一个组件,该组件提供文本框供用户输入CSS代码.无论CSS用户在texbox中输入的内容都应反映在组件中.
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.
组件html
<div>
<h1>I am h1 tag<h1>
<h2>I am h2 tag<h2>
<div>
编辑器
输出
编辑器
输出
推荐答案
没有人回答,所以回答了我自己的问题.其实这很简单.只需创建一个样式标签并应用css
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>
组件
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);
}
}
这篇关于angular2从后端配置获取组件css的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文