title: ng-src and onerror : Occasionally hiding a valid image
body: <p>In order to show a default image (instead of a broken image) when the image is not physically present, I use this piece of code:</p>
  
  <pre><code>&lt;img ng-show="order.img" ng-src="{{order.img | fPath}}" onerror="this.style.display='none';"/&gt;
  &lt;img ng-hide="order.img" ng-src="{{'default.png' | imgPath}}" /&gt;
  </code></pre>
  
  <p>Here <code>fPath</code>,<code>imgPath</code> are filters that append a prefix to the image name.</p>
  
  <p>Most of the times it works well (the image gets rendered). However, in some cases the image does not show up. In such cases, the angular snippet gets translated to this html (note the <code>style="display: none;"</code> in the first img tag):</p>
  
  <pre><code>&lt;img ng-show="order.img" ng-src="http://xx.s3.amazonaws.com/o/img1.jpg" onerror="this.style.display='none'" src="http://xx.s3.amazonaws.com/o/img1.jpg" style="display: none;"&gt;
  &lt;img ng-hide="order.img" ng-src="http://xx.s3.amazonaws.com/default.png" class="ng-hide" src="http://xx.s3.amazonaws.com/default.png" style=""&gt;
  </code></pre>
  
  <p><strong>Question</strong>: What could be the reason for this? And possible workarounds? Is it that the <code>onerror</code> gets triggered sooner than expected? </p>
  
  <p>PS: <code>http://xx.s3.amazonaws.com/o/img1.jpg</code> is a valid image path and is available.</p>
  
  <p><strong>Update</strong>: This is how the app/route/controller is defined</p>
  
  <p><em>Route</em></p>
  
  <pre><code>t_app.config(function ($stateProvider, $urlRouterProvider, $httpProvider) {
      // ...
      $stateProvider.state('ref', {
          url: '/orders/:ref',
          templateUrl: 'views/order.htm',
          controller: 'orderController'
      });
      // ...
  });
  </code></pre>
  
  <p><em>Controller</em></p>
  
  <pre><code>t_app.controller('orderController', ['$scope', '$stateParams', function($scope, $stateParams) {
        // Load the order (this step takes a while)
  }]);
  </code></pre>