title: How to change class of individual elements inside ngfor?
body: <p>I'm very sorry if this question has been answered however I was unable to find an appropriate answer. I am attempting to create a simple chat application and wish for messages sent by the current user to appear on the right hand side of the screen whilst messages from other users will appear on the left.</p>
  
  <p>I believe I am most of the way there with this however its not functioning properly, if the most recent message is sent by the current user then all the message will be on the right vica versa for messages from other users.</p>
  
  <p>My question in more detail therefor is, is there a way for me to change the class for a list item that is generated by ngFor, with each element possibly having a different class to any other list item.</p>
  
  <p>Below is the HTML:</p>
  
  <pre><code>    &lt;ion-item *ngFor="let message of messages; let i = index" (click)="beingWhisper(message)"&gt;
  
      &lt;ion-card [ngClass]="styleClass"&gt;
        &lt;ion-card-header class="messageHeader"&gt;
          {{i}}{{message.Person}}
        &lt;/ion-card-header&gt;
        &lt;ion-card-content&gt;
          {{message.Message}}
        &lt;/ion-card-content&gt;
      &lt;/ion-card&gt;
  
  &lt;/ion-item&gt;
  </code></pre>
  
  <p>Here is the very basic CSS:</p>
  
  <pre><code>.message-other{
    float: left;
    width: 50%;
  }
  .message-self{
    float: right;
    width: 50%;
  }
  </code></pre>
  
  <p>The ngClass variable is controlled simply with this variable on my component class, this is changed to be either "message-self" or "message-other" when required</p>
  
  <pre><code>    styleClass = '';
  </code></pre>
  
  <p><strong>Fixed</strong>: 
  In case anyone finds this question with a similar problem, my issue was fixed by using the individual messages property, which held the senders ID and if it was the same as the current user ID then apply the style I wanted, this was discovered through dfsq's suggestion, with thanks to Günter Zöchbauer as his suggestion was also correct</p>