title: AngularJS code in a
body: <p>I am new to AngularJS and managed to get this to work. Can I get some feedback if this is done in an "Angular way?" </p>
  
  <p>The DataResults Service just fetches some JSON data and will eventually have more methods that will process it. The part I am most curious about is the controller. It waits for the service to complete and then and then brings the data in scope. The HTML does some stuff with it, but is not relevant for this.</p>
  
  <p>Thanks for your time</p>
  
  <pre><code>var myApp = angular.module("myApp ", []);
  myApp.factory("DataResults",function($http) {
    var data = [];
  
    var promise = $http.get("/js/data.json").
      success(function(d, status, headers, config) {
        data= _.compact(d);
      }).
      error(function(d, status, headers, config) {
        return "Error!";
      });
  
    promise.getData= function() {
      return data;
    };
    /* More methods */
  
    return promise;
  });
  
  /* Controllers */
  myApp.controller("DataSearchCtrl", ["$scope", "DataResults", function($scope, DataResults) {
    DataResults.then(function() {
      $scope.data = DataResults.getData();
    });
  }]);
  </code></pre>
  
  <p>Edit: I can't comment. Yes it does work.</p>