title: Check object size in AngularJS template, doing it wrong?
body: <p>I want to iterate through <code>myObject</code> in an AngularJS template</p>
  
  <p><strong>This does not work :</strong></p>
  
  <pre><code>&lt;ul ng-if="Object.keys(myObject).length"&gt;
      &lt;li ng-repeat="(key, val) in myObject"&gt;
          Value at key {{ key }} is: {{ val }}
      &lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>Nothing shows up, I suspect because <code>$scope.Object</code> is not defined.</p>
  
  <p><strong>Instead, I did this :</strong></p>
  
  <p>In the controller/directive :</p>
  
  <pre><code>$scope.sizeOf = function(obj) {
      return Object.keys(obj).length;
  };
  </code></pre>
  
  <p>In the template :</p>
  
  <pre><code>&lt;ul ng-if="sizeOf(myObject)"&gt;
      &lt;li ng-repeat="(key, val) in myObject"&gt;
          Value at key {{ key }} is: {{ val }}
      &lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>I do not like this solution because of the duplication of this function in every single controller or directive <code>$scope</code>.</p>
  
  <p><strong>Do you see any cleaner solution?</strong></p>
  
  <p>Thanks !</p>