How to add style to inline svg in Angular 2

4.5k views Asked by At
 <div class="svg_ahu card_content" align="start" [inlineSVG]="'/assets/ahu.svg'"></div>

I used this syntax to include SVG in angular2 but not able to style it.

CSS:

 #fill1 {
  animation: fill1 .1s ease infinite;
}    
2

There are 2 answers

1
Shedar On BEST ANSWER

It's happening due to styles encapsulation.

You can use one of 3 options:

  • "encapsulation: ViewEncapsulation.None" for the component with SVG.
  • "/deep/ #fill1" selector, to specify that rules should apply to a child component
  • you can move SVG styles to the global styles.[s]css file.
3
Pardeep Jain On

try using like this

<div class="svg_ahu card_content" align="start" [attr.inlineSVG]="'/assets/ahu.svg'"></div>

`