title: Angular. How can i display error from exception handler on view?
body: <p>I want to catch, customize and display all my errors and exception on view in my application. So i'm trying to find best ways to do that. Few days ago i asked this question <a href="https://stackoverflow.com/questions/35340195/angularjs-apply-changes-to-the-view-from-the-factory">AngularJS, apply changes to the view from the factory</a>. And everything worked fine until i got a problem with injections. So i try to find best solution for displaying errors on view from factory.</p>
  
  <p>now i have a view</p>
  
  <pre><code>&lt;div class="messages"&gt;
      &lt;div class="message" ng-repeat="message in errors" ng-bind="message"&gt;&lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>and factory</p>
  
  <pre><code>services.factory('$exceptionHandler',['$injector', function ($injector) {
      return function(exception, cause){
          var $rootScope = $injector.get('$rootScope');
          var $timeout = $injector.get('$timeout');
          var message;
  
          $rootScope.errors = $rootScope.errors || [];
          switch (exception.message){
              case 'Unexpected token A':
                  message = 'Connection problem';
                  break;
              default:
                  message = exception.message;
          }
  
          $rootScope.errors.push(message);
          $timeout(function(){
              $rootScope.errors.splice(0,1);
          }, 5000);
      };
  }]);
  </code></pre>
  
  <p>and i'm trying to get rid off inserting scope into service.
  So how can i get all my exceptions in controller to displaying their on view?</p>