Angular 2 - Apply conditional style to a directive's child HTML element
<p>I am trying to apply a class to an HTML element based on a click event. This works fine when setting the class property for the child component's selector from the parent component's template as seen by the following snippet from the parent component:</p>

<pre class="lang-ts prettyprint-override"><code>[class.bordered]='isSelected(item)'
</code></pre>

<p>This will appropriately set the style when that item is clicked. However, I want to set an inner HTML element's class in the child component based on the same sort of click event, here's the desired target for the style for the child component:</p>

<pre class="lang-ts prettyprint-override"><code>template: `
  &lt;div class="This is where I really want to apply the style"&gt;  
    {{ item.val }}
  &lt;/div&gt;
`
</code></pre>

<p>Is there a way to do this that is easily supported? Or is this considered a bad practice and I should design my components to avoid this sort of conditional styling situation?</p>

<p>Full code:</p>

<pre class="lang-ts prettyprint-override"><code>@Component({
  selector: 'parent-component',
  directives: [ChildComponent],
  template: `
    &lt;child-component
      *ngFor='#item of items'
      [item]='item'
      (click)='clicked(item)'
      [class.bordered]='isSelected(item)'&gt;
    &lt;/child-component&gt;
  `
})
export class ParentComponent {
  items: Item[];
  currentItem: item;

  constructor(private i: ItemService) {
    this.items = i.items;
  }

  clicked(item: Item): void {
    this.currentItem = item;
  }

  isSelected(item: Items): boolean {
    if (!item || !this.currentItem) {
      return false;
    }
    return item.val === this.currentItem.val;
  }
}


@Component({
  selector: 'child-component',
  inputs: ['item'],
  template: `
    &lt;div class="This is where I really want to apply the style"&gt;  
      {{ item.val }}
    &lt;/div&gt;
  `
})
export class ChildComponent {}
</code></pre>