title: How to make a service funtion syncronus in angularjs
body: <p>I'm working with a project using mean.js stack. And I need to make a function that I can use in every other module. I've been reading and what I've found was that I have to make the function as a service. Right this is how I have my service <code>getSchoolByUser()</code>:</p>
  
  <pre><code>angular.module('schools').factory('Schools', ['$resource',
    function($resource) {
      return $resource('api/schools/:schoolId', {
        schoolId: '@id'
      }, {
        update: {
          method: 'PUT'
        },
        getSchoolByUser: {
          url: 'api/schoolByUser/:schoolPrincipalId',
          params: {
              schoolPrincipalId: 'schoolPrincipalId'
          },
          isArray: false
        }
      });
    }
  ]);
  </code></pre>
  
  <p>This function I going to use it every time I create a new catalogue. This is an example that how I use it on my CourseController to create a new Course:</p>
  
  <pre><code>angular.module('courses')
    .controller('CoursesController', ['$scope',
      '$stateParams',
      '$location', 'Authentication',
      'Courses','Schools',
  
      function($scope, $stateParams, $location, Authentication, Courses, Schools) {
        $scope.authentication = Authentication;
  
  
        // Create new course
        $scope.create = function(isValid) {
          $scope.error = null;
  
          if (!isValid) {
            $scope.$broadcast('show-errors-check-validity', 'courseForm');
  
            return false;
          }
  
          var course = new Courses($scope.course);
  
          $scope.school = Schools.getSchoolByUser({schoolPrincipalId: $scope.authentication.user.id
          }, function () {
            course.SchoolId = $scope.school.id;
            console.log(course);
            course.$save(function(response) {
              //some code here
            }, function(errorResponse) {
              $scope.error = errorResponse.data.message;
            });
          });
        };
  
      }
    ]);
  </code></pre>
  
  <p>Is there a way that I can go this in a synchronous way with a return inside of the function so I can assign it directly to the scope and the just proceed to save like this:</p>
  
  <pre><code>course.SchoolId = getSchoolByUser();
  course.$save(function(response) {
  </code></pre>