Angular: Empty Fiddle

http://angularjs.org/

by marcolepsy

HTML

<script src="http://code.angularjs.org/angular-1.0.1.js"></script>
<div ng-app="myApp" ng-controller="MyCtrl">
  {{vals}}
</div>

JavaScript

var myApp = angular.module('myApp', []);

myApp.factory('loadService', function($q, $timeout) {
  return {
    getJs: function(path) {
      var deferred = $q.defer();

      deferred.resolve('Value 1');

      return deferred.promise;
    }
  }
});

myApp.controller('MyCtrl',function($scope, mymodService) {
    mymodService.readIt(0);
   $scope.vals = mymodService.getVals();
});
    

myApp.service('mymodService', function(loadService) {
  
  vals = {};
  this.readIt = function (pos) {
      loadService.getJs().then(function(data) {
          vals[pos] = data;
          console.log('data ',this.vals[pos]);
      });   
  }
  
  this.getVals = function() {
     console.log(window.vals);
      return vals;
  };
});