简体   繁体   English

Typescript Angular 5 动态添加 css 到组件

[英]Typescript Angular 5 add dynamically css to component

I have a really special issue.我有一个非常特殊的问题。 I am using AngularTS with C# on serverside and Typescript on clientside.我在服务器端使用 AngularTS 和 C#,在客户端使用 Typescript。

I want to add to our application the possibility, that the customer can add css styles in a textbox or add file locations (external).我想向我们的应用程序添加可能性,即客户可以在文本框中添加 css 样式或添加文件位置(外部)。

In a custom component I want to add the html code from the official site of the customer.在自定义组件中,我想添加来自客户官方网站的 html 代码。 The customer should add the css files or text in order to show the content on our page like the content of the official site.客户应添加 css 文件或文本,以便像官方网站的内容一样显示我们页面上的内容。

Unfortunately I could not find a possibility to add the css files.不幸的是,我找不到添加 css 文件的可能性。

@Component({
selector: 'customer-footer',
templateUrl: './customer-footer.component.html'
styleUrls: getCSS()})




export function getCSS(): string [] {
var styles: string[] = [];

styles.push("https://");

return styles;}

This doesn't work because AOT is not compatible with static refs.这不起作用,因为 AOT 与静态引用不兼容。

I tried to add the css Content in styles Tag (Body-Area):我尝试在样式标签(Body-Area)中添加 css 内容:

 <style type="text/css"> {{footerCSS}}</style>

My best result was to add a Object (css) in ngStyle to the displaying .我最好的结果是在 ngStyle 中添加一个对象(css)到显示 .

 <div *ngIf="!fixedBottom" [innerHtml]="footerHtml" [ngStyle]="footerCSS"></div>

Unfortunately I could not find a way to convert css code like this one:不幸的是,我找不到像这样转换 css 代码的方法:

 .flatWeatherPlugin { font-size: inherit; width: 100%; } .flatWeatherPlugin p, .flatWeatherPlugin h2, .flatWeatherPlugin h3, .flatWeatherPlugin ul, .flatWeatherPlugin li { padding: 0; margin: 0; color: inherit; }

To a functional object.到一个功能对象。 Has someone an idea or a helpful message?有人有想法或有用的信息吗?

在打字稿中,您可以使用它来动态加载 css require('css/stylesheet.css')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM