title: Angularjs resource service example
body: <p>I've been stuggling with angularjs services ans resource for a while, and can't get what I'm missing. </p>
  
  <p>Here is a fiddle of my example:
  <a href="http://jsfiddle.net/spacm/bfUVj/47/" rel="nofollow">http://jsfiddle.net/spacm/bfUVj/47/</a>
  (code below details)</p>
  
  <p>This fiddle attempts to load periods (2012-2013,2013-2014...) from a web resource, to fill a select.</p>
  
  <p>The fiddle doesn't work, I expect the $scope.perriodeJson to be filled by the periodes service. The http get request runs, but I only get an empty object, and don't get any update of the promise I expect.
  Thanx for pointing what's wrong in this code, and suggesting enhancements.</p>
  
  
  
  <pre><code>&lt;div ng-app='mod_periodes'&gt;
      &lt;div id="appChoixPeriode" ng-controller='CtrlChoixPeriode'&gt;
          test:{{test}}&lt;hr&gt;
          json periodes:{{periodeJson}}&lt;hr&gt;
          Select periode: 
          &lt;select ng-model="periodeSelect" ng-options="item.name for item in periodeSelectModel" ng-change="changePeriodeUtilisee()"&gt;&lt;/select&gt;
  
          &lt;button type='button' ng-click='resetDefaultPeriode()'&gt;G&lt;/button&gt;
      &lt;/div&gt;&lt;!--appChoixPeriode--&gt;
  &lt;/div&gt;
  
  angular.module('mod_periodes', ['ngResource']);
  
  angular.module('mod_periodes').factory('periodes', function($resource) {
        var  res = $resource('http://emm.menard.free.fr/test/fakereq.html');
      /*content returned:
      {"status":"success",
      "data":{
          "periodes":[
              {"id_periode":"1","name":"2012-2013","ts_debut":"2012-07-01 00:00:00","ts_fin":"2013-06-30 23:59:59"},
              {id_periode":"2","name":"2013-2014","ts_debut":"2013-07-01 00:00:00","ts_fin":"2014-06-30 23:59:59"},
              {"id_periode":"3","name":"2014-2015","ts_debut":"2014-07-01 00:00:00","ts_fin":"2015-06-30 23:59:59"}
              ],
          "id_periode":"2",
          "temps_periode_utilisee":"present"},
      "messages":[]}
      */
        return res;
  });
  
  angular.module('mod_periodes').controller('CtrlChoixPeriode',implCtrlChoixPeriode);
  
  function implCtrlChoixPeriode($scope, $resource, periodes) {
      $scope.test="angular works";
      $scope.periodeJson=periodes.get(); //why dont I get anything in $scope.periodeJson??
      //the http request runs and looks successful
  
      //below this, what I intended to do once I retrieve data
     /* $scope.periodeJson=periodes.get(function() {
          $scope.periodeSelectModel=$scope.periodeJson.data.periodes;
          $scope.periodeSelect=$scope.periodeSelectModel[1];
      });*/
  //   $scope.periodeSelectModel=$scope.periodeJson.data.periodes;
  //   $scope.periodeSelect=$scope.periodeSelectModel[1];
  }
  </code></pre>