note.js 831 B

12345678910111213141516171819202122232425262728293031
  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. create: function (note) {
  20. return $http({
  21. method: "PUT",
  22. url: "/notes",
  23. data: note,
  24. });
  25. },
  26. }
  27. }]);