forked from Avdhesh-Varshney/WebMasterLog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
34 lines (29 loc) · 1.15 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// AngularJS
angular.module('QuickNotesApp', [])
.controller('NotesController', function ($scope) {
// Initialize notes array
$scope.notes = [];
// Load notes from local storage when the page loads
if (localStorage.getItem('notes')) {
$scope.notes = JSON.parse(localStorage.getItem('notes'));
}
// Function to add a new note
$scope.addNote = function () {
if ($scope.newNote.title && $scope.newNote.body) {
$scope.notes.push({
title: $scope.newNote.title,
body: $scope.newNote.body
});
$scope.newNote.title = '';
$scope.newNote.body = '';
// Save notes to local storage
localStorage.setItem('notes', JSON.stringify($scope.notes));
}
};
// Function to remove a note
$scope.removeNote = function (index) {
$scope.notes.splice(index, 1);
// Save notes to local storage
localStorage.setItem('notes', JSON.stringify($scope.notes));
};
});