title: How to create selector to select an item by id from ngrx store
body: <p>I read ngrx store's <a href="https://github.com/ngrx/platform/blob/master/docs/store/selectors.md" rel="noreferrer">documentation</a> about selectors and need to figure out how to create a selector in order to select one item by item id. I already can do this as part of store subscription when I get all of the items from <code>selectAllItems</code> selector, but I need to figure out how to select specific item out of a list of items in the store. My main reason is that <code>createSelector</code> offers performance gains that I like to benefit from.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>import { AppState, Item } from '../../shared/models/index';
  import { createSelector } from '@ngrx/store';
  
  export const selectItems = (state: AppState) =&gt; state.eventsState;
  
  export const selectAllItems = createSelector(selectItems, (allItems: { items: Item[] }) =&gt; {
    if (allItems &amp;&amp; allItems.items) {
     return allItems.items.filter((item: Item) =&gt; (!item.active &amp;&amp; !item.closed));
    } else {
      return allItems.items;
    }
  });
  </code></pre>
  
  <p>Then in my controller i filter by id to get needed item:</p>
  
  <pre><code>this.store.select(selectors.selectAllItems)
    .filter(data =&gt; data !== null)
    .subscribe(allItems =&gt; {
      this.item = allItems.filter(item =&gt; {
        return item.id === this.navParams.data.id;
      });
    });
  </code></pre>
  
  <p>I would like to be able to create a selector for that specific item and use it like so:</p>
  
  <pre><code>this.store.select(selectors.selectItemById(this.navParams.data.id))
    .filter(data =&gt; data !== null)
    .subscribe(selectedItem =&gt; {
      this.item = selectedItem;
    });
  </code></pre>
  
  <p>Any help will be appreciated.</p>