note.js 1004 B

12345678910111213141516171819202122232425262728293031323334353637
  1. app.controller('NoteCtrl', ['$scope', '$http', function($scope, $http) {
  2. $http.get('js/app/note/notes.json').then(function (resp) {
  3. $scope.notes = resp.data.notes;
  4. // set default note
  5. $scope.note = $scope.notes[0];
  6. $scope.notes[0].selected = true;
  7. });
  8. $scope.colors = ['primary', 'info', 'success', 'warning', 'danger', 'dark'];
  9. $scope.createNote = function(){
  10. var note = {
  11. content: 'New note',
  12. color: $scope.colors[Math.floor((Math.random()*3))],
  13. date: Date.now()
  14. };
  15. $scope.notes.push(note);
  16. $scope.selectNote(note);
  17. }
  18. $scope.deleteNote = function(note){
  19. $scope.notes.splice($scope.notes.indexOf(note), 1);
  20. if(note.selected){
  21. $scope.note = $scope.notes[0];
  22. $scope.notes.length && ($scope.notes[0].selected = true);
  23. }
  24. }
  25. $scope.selectNote = function(note){
  26. angular.forEach($scope.notes, function(note) {
  27. note.selected = false;
  28. });
  29. $scope.note = note;
  30. $scope.note.selected = true;
  31. }
  32. }]);