SHARE
TWEET

Untitled

a guest Jan 26th, 2016 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #### Output
  2. controller before this.note
  3.  
  4. controller after this.note
  5.  
  6. interceptor
  7.  
  8.  
  9. ##### Controller
  10. angular.module('DiaryApp').controller('NoteEditController', ['Note','$routeParams', '$location', function(noteService, $routeParams, $location) {
  11.     console.log('controller before this.note');
  12.     this.note = noteService.get({id: $routeParams.id});
  13.     console.log('controller after this.note');
  14.  
  15. #### Resource
  16. angular.module('DiaryApp').factory('Note', ['$resource', function($resource) {
  17.  
  18.   function parseResponseDates(response) {
  19.     var data = response.data, key, value;
  20.     for (key in data) {
  21.       if (!data.hasOwnProperty(key) &&  toString.call(data[key]) !== '[object String]') continue;
  22.       value = Date.parse(data[key]);
  23.       if(!isNaN(value)) data[key] = value;
  24.     }
  25.     console.log('interceptor');
  26.     return response;
  27.   }
  28.  
  29.   return $resource('/notes/:id', {id: "@id"},
  30.       {
  31.           'update': {
  32.             method:'PUT'
  33.           },
  34.           'get': {
  35.             method: 'GET',
  36.             interceptor: {response: parseResponseDates}
  37.           }
  38.       });
  39.   }]);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top