services.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. angular.module('starter.services', [])
  2. .factory('Chats', function() {
  3. // Might use a resource here that returns a JSON array
  4. // Some fake testing data
  5. var chats = [{
  6. id: 0,
  7. name: 'Ben Sparrow',
  8. lastText: 'You on your way?',
  9. face: 'img/ben.png'
  10. }, {
  11. id: 1,
  12. name: 'Max Lynx',
  13. lastText: 'Hey, it\'s me',
  14. face: 'img/max.png'
  15. }, {
  16. id: 2,
  17. name: 'Adam Bradleyson',
  18. lastText: 'I should buy a boat',
  19. face: 'img/adam.jpg'
  20. }, {
  21. id: 3,
  22. name: 'Perry Governor',
  23. lastText: 'Look at my mukluks!',
  24. face: 'img/perry.png'
  25. }, {
  26. id: 4,
  27. name: 'Mike Harrington',
  28. lastText: 'This is wicked good ice cream.',
  29. face: 'img/mike.png'
  30. }];
  31. return {
  32. all: function() {
  33. return chats;
  34. },
  35. remove: function(chat) {
  36. chats.splice(chats.indexOf(chat), 1);
  37. },
  38. get: function(chatId) {
  39. for (var i = 0; i < chats.length; i++) {
  40. if (chats[i].id === parseInt(chatId)) {
  41. return chats[i];
  42. }
  43. }
  44. return null;
  45. }
  46. };
  47. });