title: How to access an object attribute inside a service in AngularJS?
body: <p>I have a service with a local variable object with events names:</p>
  
  <pre><code>    myApp.service('appService', ['$rootScope', function ($rootScope) {
  
          var events = {
              firstEvent: "MyFirstEvent",
              secondEvent: "MySecondEvent"
          };
  
          this.doEvent = function(eventName)
         {           
              // do something...
         };
  
  
      }]);
  </code></pre>
  
  <p>Now I am trying to read <strong><em>events.firstEvent</em></strong> inside a controller:</p>
  
  <pre><code>myApp.controller('myController', ['$scope', 'appervice', function ($scope, appService) {
  
  var mydata = appService.events.firstEvent;
  
  }]);
  </code></pre>
  
  <p>The problem I get this error in console:</p>
  
  <pre><code>TypeError: Cannot read property 'firstEvent' of undefined
  </code></pre>
  
  <p>What I'm doing wrong? </p>
  
  <p>P.S.
  I also can not access the function doEvent().</p>