title: How to dynamically set complex CSS of an Angular 2+ component?
body: <p>I'd like to ask for a little nudge to get my brain out of the box I got it into.</p>
  
  <p><strong>Context</strong></p>
  
  <p>Angular 4 using Angular CLI and AoT.</p>
  
  <p>All methods mentioned in <a href="https://angular.io/docs/ts/latest/guide/component-styles.html" rel="nofollow noreferrer">https://angular.io/docs/ts/latest/guide/component-styles.html</a> describe ways to set complex CSS of a component while it is being written by a developer.</p>
  
  <p>After a component is created, Angular allows to adjust individual styles and even assign various CSS class names to tags in the component as you please, all that using <code>[ngClass]</code>, <code>&lt;div [class.something]="condition"&gt;</code>, various <code>@HostBinding</code> decorators and some other methods.</p>
  
  <p>However, none of the above can change the CSS declaration the component is using. The methods above can either (a) use what is already available in the stylesheet defined by the developer or (b) set individual CSS properties to individual HTML tags in the component's template.</p>
  
  <p><strong>Question</strong></p>
  
  <p>How would I update the CSS for the whole component on runtime so that all elements in that component respond to the new CSS?</p>
  
  <p>Say I introduce a new style for a div.someClass and I want all matching elements div.someClass to reflect the new style.</p>
  
  <p><strong>Plunker</strong></p>
  
  <p>A showcase of my attempts is here: <a href="https://plnkr.co/edit/N2C40cSb7hd1AyOxWWdT" rel="nofollow noreferrer">https://plnkr.co/edit/N2C40cSb7hd1AyOxWWdT</a></p>
  
  <p>The button should be red, based on the value of <code>MyChildComponent.styles</code></p>
  
  <p>I think I understand why it doesn't work the way I would expect: shortly said, styles are built in the component during compilation, not runtime, including those found inside <code>&lt;style /&gt;</code> tags in the template. </p>
  
  <p>But knowing why it doesn't work doesn't help me to make it work. </p>
  
  <p>Any help highly appreciated.</p>