title: Using *ngFor to loop through an array and *ngIf to select which elements from the array to list
body: <p>I'm trying to use <code>*ngFor</code> to loop through an array of objects. I realized I couldn't use <code>*ngFor</code> and an <code>*ngIf</code> on the same element, it would return an error. Instead, I tried to stick my <code>*ngIf</code> on the contents of the list item. But now, I'm getting a bunch of empty list items and they're being created and displayed on my view page.</p>
  
  <p>I don't want to stick the <code>*ngFor</code> on my <code>&lt;ul&gt;</code> element because then it will create a bunch of <code>&lt;ul&gt;</code> elements with a single list item within each.</p>
  
  <p>I'm hoping one of you will have another method of implementing this. </p>
  
  <pre><code>// AppComponent
  // contacts: Contact[];  // An array of `Contact` Objects
  
  &lt;ul&gt;
    &lt;li *ngFor="#contact of contacts"&gt;
      &lt;contact-detail *ngIf="checkList(contact) == true" [contact]="contact"&gt;&lt;/contact-detail&gt;
    &lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>and...</p>
  
  <pre><code>// ContactDetailComponent
  &lt;img /&gt;
  &lt;span&gt;{{contact.name}}&lt;/span&gt;
  &lt;span&gt;{{contact.email}}&lt;/span&gt;
  </code></pre>
  
  <p>What is happening:</p>
  
  <pre><code>&lt;ul&gt;
    &lt;li&gt;
      &lt;!--template bindings={}--&gt;  // ngIf conditional returned true
      &lt;img /&gt;
      &lt;span&gt;Name1&lt;/span&gt;
      &lt;span&gt;Email1&lt;/span&gt;
    &lt;/li&gt;
    &lt;li&gt;
      &lt;!--template bindings={}--&gt;   // ngIf conditional returned false
    &lt;/li&gt;
    &lt;li&gt;
      &lt;!--template bindings={}--&gt;  // false
    &lt;/li&gt;
    &lt;li&gt;
      &lt;!--template bindings={}--&gt;  // true
      &lt;img /&gt;
      &lt;span&gt;Name1&lt;/span&gt;
      &lt;span&gt;Email1&lt;/span&gt;
    &lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>I'm using Material Design Lite, so all these elements will have some css properties. Empty <code>&lt;li&gt;</code> just return an empty space of a certain height. </p>
  
  <p>Also, if other information is needed, please let me know.</p>