title: Angularjs service undefined
body: <p>Was building out an angular application, but am getting error undefined with the service or factory. Specifically "can not read property of setName undefined".  I have went <a href="http://www.dotnet-tricks.com/Tutorial/angularjs/V2YS090914-Understanding-AngularJS-Factory,-Service-and-Provider.html" rel="nofollow">here</a> to figure out my error. Even changed around my syntax figuring I maybe had something out of place but still throwing an undefined error.</p>
  
  <p>Here is the controller:</p>
  
  <pre><code>(function() {
    "use strict";
    angular
      .module("app", [])
      .controller("mainCtrl", ["$scope", mainCtrl]);
  
    function mainCtrl($scope, productService) {
  
      $scope.testService = productService.setName("Data Service");
    }
  }());
  </code></pre>
  
  <p>Here is the service script:</p>
  
  <pre><code>(function() {
    "use strict";
    angular
      .module("app")
      .service("productService", function() {
  
        var serviceObj = {};
        serviceObj.name = '';
        serviceObj.setName = function(newName) {
          serviceObj.name = newName;
        };
        return serviceObj;
      });
  }());
  </code></pre>
  
  <p>Originally, I had the service as :</p>
  
  <pre><code>(function() {
    "use strict";
    angular
      .module("app")
      .service("productService", setName);
  
    function setName(newName) {
      var serviceObj = {};
      serviceObj.name = '';
      serviceObj.setName = function(newName) {
        serviceObj.name = newName;
      };
      return serviceObj;
    }
  }());
  </code></pre>