note.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. There are 5 types of services:
  3. * Factory: most common. Used to share functions and objects across an app.
  4. * Value: often used, just share a value
  5. * Provider: common. Like factory, but with configuration
  6. * Constant: rarely used, to share a value within app configuration.
  7. * Service: rarely used, a ServiceService recipe (?) to share instances of methods and objects.
  8. */
  9. angular.module("noteWrangler")
  10. // Naming the function <service>Factory is a common convention.
  11. .factory('Note', ['$http', function NoteFactory($http) {
  12. return {
  13. all: function () {
  14. return $http({
  15. method: "GET",
  16. url: "/notes.json",
  17. });
  18. },
  19. find: function (id) {
  20. return $http({
  21. method: "GET",
  22. url: "/notes/" + id.toString(),
  23. });
  24. },
  25. create: function (noteObj) {
  26. return $http({
  27. method: "POST",
  28. url: "/notes",
  29. data: noteObj,
  30. });
  31. },
  32. update: function (nodeObj) {
  33. return $http({
  34. method: "PUT",
  35. url: "/notes",
  36. data: nodeObj,
  37. })
  38. },
  39. }
  40. }]);