Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
245 views
in Technique[技术] by (71.8m points)

javascript - SASS styles injected by innerHTML don't work

I want to inject style to div in component. My issue is it's scss and in application we use scss but style does not want to work. When inject the same style as css one. 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?

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>
question from:https://stackoverflow.com/questions/65602798/sass-styles-injected-by-innerhtml-dont-work

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Import the styles not in the template but in the component itself.

Look in Angular docs https://angular.io/guide/component-styles


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...