title: Angularjs - Factory service not able to access $scope objects
body: <p>Based on the top answer of the question asked at : <a href="https://stackoverflow.com/questions/22080262/how-to-call-custom-javascript-functions-from-an-angularjs-controller">How to call custom Javascript functions from an AngularJS controller?</a>.</p>
  
  <p>I tried following code: </p>
  
  <pre><code>&lt;body ng-app="FDAApp" ng-controller="formController"&gt;
  &lt;form ng-submit="login()"&gt;
      &lt;input type="submit" ng-click="ngSubmit()"&gt;
  &lt;/form&gt;
  &lt;script type="text/javascript" &gt;
      var app = angular.module('FDAApp', []);
      angular.module('FDAApp').factory('MyService', function($http) {
          var sessionKey='';
          return {
              sessionKey: sessionKey,
              login: function()
              {
                  sessionKey="ABCD";
              }
          }
      });
  
      app.controller('formController', function ($scope, $http, $templateCache, $interval, $timeout, MyService) {
  
          $scope.sessionKey = '';
          $scope.sessionKey = MyService.sessionKey;
  
          $scope.login = function () {
              MyService.login();
              console.log($scope.sessionKey);
          }
      });
  &lt;/script&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>Problem: I am not able get value of $scope.sessionKey updated. Any help?</p>