0

I have some angular code that contains some inline styles that I need to remove. Reason being is we need this code to be CSP compliant and CSP has issues with inline styles.

<div class="ccav-notify-pannel-wrapper" *ngIf="ccavShowWarningPanel" [style.display] ="!collapseAccountOverview? 'inherit': none">

What is a different way I can implement this exact logic maybe in typescript without using inline styles?

julian reeves
  • 39
  • 1
  • 4
  • 1
    Instead of `[style.display]` you can use https://angular.io/api/common/NgClass and move styles to separate file. – mwl Jul 21 '23 at 15:06
  • Alternatively, you could consider securing scripts with CSP which use nonce's and allow `unsafe-inline`. https://angular.io/guide/security#content-security-policy – Joosep Parts Jul 22 '23 at 07:23

1 Answers1

0

You can use ngClass directives, red and green are css class names

<td [ngClass]="val > 10 ? 'red' : 'green'">{{ val }}</td>
AliRhz
  • 39
  • 4