You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.6 KiB

  1. angular.module('thoughtsApp', [])
  2. .controller('ThoughtsController', function() {
  3. var thoughtsList = this;
  4. thoughtsList.thoughts = [
  5. {
  6. time: '9h',
  7. content:'primer thought',
  8. username: 'user1',
  9. fav: '',
  10. avatar: 'bat'
  11. },
  12. {
  13. time: '10h',
  14. content:'quart thought',
  15. username: 'user4',
  16. fav: '',
  17. avatar: 'tiger'
  18. },
  19. {
  20. time: '10h',
  21. content:'segon thought, aquí, provant',
  22. username: 'user2',
  23. fav: '',
  24. avatar: 'toucan'
  25. },
  26. {
  27. time: '10h',
  28. content:'tercer thought, responent',
  29. username: 'user1',
  30. fav: '',
  31. avatar: 'bat'
  32. },
  33. {
  34. time: '10h',
  35. content:'hola com va',
  36. username: 'user3',
  37. fav: '',
  38. avatar: 'macaw'
  39. },
  40. {
  41. time: '10h',
  42. content:'quart thought',
  43. username: 'user5',
  44. fav: '',
  45. avatar: 'giraffe'
  46. }];
  47. thoughtsList.addTodo = function() {
  48. todoList.todos.push({text:todoList.todoText, done:false});
  49. todoList.todoText = '';
  50. };
  51. thoughtsList.remaining = function() {
  52. var count = 0;
  53. angular.forEach(todoList.todos, function(todo) {
  54. count += todo.done ? 0 : 1;
  55. });
  56. return count;
  57. };
  58. thoughtsList.archive = function() {
  59. var oldTodos = todoList.todos;
  60. todoList.todos = [];
  61. angular.forEach(oldTodos, function(todo) {
  62. if (!todo.done) todoList.todos.push(todo);
  63. });
  64. };
  65. });