简体   繁体   English

由innerHTML注入的SASS styles不起作用

[英]SASS styles injected by innerHTML don't work

I want to inject style to div in component.我想将样式注入组件中的 div。 My issue is it's scss and in application we use scss but style does not want to work.我的问题是它是 scss,在应用程序中我们使用 scss 但样式不想工作。 When inject the same style as css one.注入时与css同款一个。 Everything works fine.一切正常。 The question is how can I force my component to execute style like this?问题是如何强制我的组件执行这样的样式? Is it even possible or should I convert scss style to css one?甚至有可能还是我应该将 scss 样式转换为 css 之一?

HTML.TS HTML.TS

  <div id="myExampleId">
    <div #htmlContainer [innerHtml]="htmlToDisplay | safehtml"></div>
  </div>

Style to display in component:在组件中显示的样式:

 <style> #myExampleId { table { border-collapse: collapse; width: 100%; } th{ background-color:#fe996b; } td, th { border: 1px solid #999; padding: 0.5rem; text-align: left; } body { background-color: #fe996b; } } </style>

Import the styles not in the template but in the component itself.不是在模板中而是在组件本身中导入 styles。

Look in Angular docs https://angular.io/guide/component-styles查看 Angular 文档https://angular.io/guide/component-styles

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

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