title: Angular JS filters using Firebase data
body: <p>I have some data in firebase that looks like this:</p>
  
  <pre><code>|
  |
  --users
      |
      --1
        |
        --email:"hello@gmail.com"
        --name:"User 01"
      --2
        |
        --email:"hello2@gmail.com"
        --name:"User 02"
  --chat
      |
      ---JU9ZpBj7P9dWgNYN4To
        |
        --email:"hello@gmail.com"
        --content:"Hi, i'm user 01! How are you?"
        --user:"1"
        --timestamp:"123456789"
      ---JX8ZpBnli7hliwehlfi
        |
        --email:"hello2@gmail.com"
        --content:"Hi, i'm user 02! I'm great thanks!"
        --user:"2"
        --timestamp:"123456789"
  </code></pre>
  
  <p>I get the chat data from firebase in an object called 'messages', and my HTML/angular looks like this:</p>
  
  <pre><code>&lt;ul class="chat" ng-repeat="message in messages  | orderByPriority | reverse"&gt;
      &lt;li&gt;
          &lt;strong&gt;{{message.user | uid2name}}&lt;/strong&gt; {{message.content}}
      &lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>So what I want to do is grab message.user and convert it from a userid into a name. I figured a good way would be to use a filter:</p>
  
  <pre><code>.filter('uid2name', function(loginService, $rootScope) {
  
  // Takes a userid and outputs a users name
  return function(input) {
        var ref = new Firebase('https://&lt;myapp&gt;.firebaseio.com/users/' + input);
        return $firebase(ref).name;
  };
  })
  </code></pre>
  
  <p>Now this works fine, but it does so by essentially polling firebase multiple times per second - not what I want to do at all. I have thought about caching the response in $rootScope but this seems a bit sloppy. What's the best way going about this? I am open to any ideas, I am not wed to the idea of using a filter.</p>