title: Ionic header item count
body: <p>I want my nav-bar to be able to count items placed in basket. </p>
  
  <p>Part of <code>index.html</code>:</p>
  
  <pre><code>&lt;ion-nav-bar class="bar-dark" ng-controller="navBarCtrl"&gt;
              &lt;ion-nav-back-button class="button-icon icon ion-ios-arrow-back"&gt;&lt;/ion-nav-back-button&gt;
              &lt;ion-nav-buttons side="secondary"&gt;
                  &lt;div ng-include="" src="'templates/partials/navigation.html'"&gt;&lt;/div&gt;
              &lt;/ion-nav-buttons&gt;
          &lt;/ion-nav-bar&gt;
  </code></pre>
  
  <p>Here is the nav-bar partial:</p>
  
  <pre><code>&lt;div&gt;
      &lt;a class="button button-icon icon ion-person" ng-href="#/editUserDetails"&gt;&lt;/a&gt;
      &lt;a class="button button-icon icon ion-android-cart" ng-href="#/cart"&gt;
          &lt;span class="badge badge-assertive"&gt;{{item.count}}&lt;/span&gt;
      &lt;/a&gt;
      &lt;button class="button button-icon icon ion-android-more-vertical" ng-click="showActionsheet()"&gt;&lt;/button&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>And here is <code>navBarCtrl</code>which returns item count from API:</p>
  
  <pre><code>.controller('navBarCtrl', ['Injection', '$scope', '$http', 'SERVER', function (Injection, $scope, $http, SERVER) {
          Injection.ResourceFactory.getResource($http, SERVER, 'order/itemCount')
              .then(function (response) {
                  $scope.item = {count: response.data.itemCount};
                  localStorage.setItem('countItem', response.data.itemCount);
              });
      }])
  </code></pre>
  
  <p><strong>Problem</strong>:</p>
  
  <p>When traversing between views the count doesn't update, and upon using Chrome inspection tool, the network shows that route is not called more than one time when I run the app. If I refresh with F5 the count updates...how could I fix that?</p>
  
  <p><strong>EDIT</strong>:</p>
  
  <p>Count update in API (Laravel PHP):</p>
  
  <pre><code>public function orderItemCount()
      {
          $user = $this-&gt;authUserAndCreateOrder();
          $count = $user-&gt;orders-&gt;last()-&gt;order_items-&gt;count();
          if (!empty($count)) {
              return Response::json([
                  'itemCount' =&gt; $count,
              ]);
          }
          return Response::json([
              'itemCount' =&gt; 0,
          ]);
      }
  </code></pre>
  
  <p>I have also tried setting it manually when item is placed in the cart so that local storage updates:</p>
  
  <pre><code>confirmAddingToCartPopup: function ($ionicPopup, $state, $scope) {
                  $ionicPopup.confirm({
  
                      //...
  
                  });
                  $scope.item = {count:localStorage.getItem('countItem')};
                  localStorage.setItem('countItem', ++$scope.item.count);
              },
  </code></pre>