title: Ascribe a variable to JSON Angular
body: <p>How to ascribe a variable to JSON <code>name</code>? </p>
  
  <p><strong>JSON <code>names</code> object</strong></p>
  
  <pre><code>[
      { "name": "John", "age" : "12" },
      { "name": "Ben", "age" : "15" },
      { "name": "Jason", "age" : "18" },
      { "name": "Billy", "age" : "11" }
  ]
  </code></pre>
  
  <p><strong>Angular service and controller</strong></p>
  
  <pre><code>var app = angular.module('app', []);
      app.service('service', function($http, $q){
          var deferred = $q.defer();
  
          $http.get("jsonfile.json").then(function(data){
              deferred.resolve(data);
          });
  
          this.getNames = function(){
              return deferred.promise;
          }
      });
      app.controller('secondCtrl', function($scope, service){
          var promise = service.getNames();
          promise.then(function(data){
              $scope.names = data.data;
              console.log($scope.names);
  
          });
  });
  </code></pre>
  
  <p>What I tried to do in controller: </p>
  
  <pre><code>var name = names.name;
  </code></pre>
  
  <p>And then I tried in HTML <code>ng-repeat {{name}}</code> but it didn't work.</p>