Disclaimer: this answer only applies if you are required to inject html as a string. For example if you receive the string from an api. Otherwise you should be using Angular directives to generate the content.
This is because Angular uses View Encapsulation. It does this by generating a unique identifier and adding it as an attribute to all of your html elements in the component, something like _ngcontent-nxs-c94="". Then it appends [_ngcontent-nxs-c94] to all of your css declarations inside the component. Inspect your elements and you’ll see what I mean.
If you’re injecting html after the component has been compiled, that html will obviously not have the attribute and your css will not affect it. You’re not meant to inject html like this, since Angular provides all of the tools to generate content dynamically. But if it’s absolutely required then you just need to add the CSS globally (ie. it does not get the unique attribute appended). Any file in the styles array located in angular.json will be compiled as a global style, by default styles.css is the only file here.
So just add your css to a file that that is in the styles array. Either in styles.css or create your own (you can make it right next to your original css file). But this brings us back to the days before View Encapsulation, so we need to make sure the selectors are unique. That’s pretty simple since you can just wrap all of the css in your component’s html tag. Keep in mind this will affect any other nested components so you may need to add some more unique class names.
So this lets you apply global styles to a component while still maintaining view encapsulation within your original css file. The other option is to disable view encapsulation for the component, but I wouldn’t recommend, since there may be css that you do want encapsulated.
You can generate the list dynamically in the html using angular. I would setup my a caret object / list in my component and then take advantage of *ngFor and [ngClass] to achieve what you’re trying to do. Something like: