+
+
+
diff --git a/src/js/controllers/main.js b/src/js/controllers/main.js
new file mode 100644
index 0000000..7cb2ce2
--- /dev/null
+++ b/src/js/controllers/main.js
@@ -0,0 +1,50 @@
+angular.module('todoController', [])
+
+ // inject the Todo service factory into our controller
+ .controller('mainController', ['$scope','$http','Todos', function($scope, $http, Todos) {
+ $scope.formData = {};
+ $scope.loading = true;
+
+ // GET =====================================================================
+ // when landing on the page, get all todos and show them
+ // use the service to get all the todos
+ Todos.get()
+ .success(function(data) {
+ $scope.todos = data;
+ $scope.loading = false;
+ });
+
+ // CREATE ==================================================================
+ // when submitting the add form, send the text to the node API
+ $scope.createTodo = function() {
+
+ // validate the formData to make sure that something is there
+ // if form is empty, nothing will happen
+ if ($scope.formData.text != undefined) {
+ $scope.loading = true;
+
+ // call the create function from our service (returns a promise object)
+ Todos.create($scope.formData)
+
+ // if successful creation, call our get function to get all the new todos
+ .success(function(data) {
+ $scope.loading = false;
+ $scope.formData = {}; // clear the form so our user is ready to enter another
+ $scope.todos = data; // assign our new list of todos
+ });
+ }
+ };
+
+ // DELETE ==================================================================
+ // delete a todo after checking it
+ $scope.deleteTodo = function(id) {
+ $scope.loading = true;
+
+ Todos.delete(id)
+ // if successful creation, call our get function to get all the new todos
+ .success(function(data) {
+ $scope.loading = false;
+ $scope.todos = data; // assign our new list of todos
+ });
+ };
+ }]);
\ No newline at end of file
diff --git a/src/js/core.js b/src/js/core.js
new file mode 100644
index 0000000..28dbeed
--- /dev/null
+++ b/src/js/core.js
@@ -0,0 +1 @@
+angular.module('scotchTodo', ['todoController', 'todoService']);
diff --git a/src/js/services/todos.js b/src/js/services/todos.js
new file mode 100644
index 0000000..49761e7
--- /dev/null
+++ b/src/js/services/todos.js
@@ -0,0 +1,17 @@
+angular.module('todoService', [])
+
+ // super simple service
+ // each function returns a promise object
+ .factory('Todos', ['$http',function($http) {
+ return {
+ get : function() {
+ return $http.get('/api/todos');
+ },
+ create : function(todoData) {
+ return $http.post('/api/todos', todoData);
+ },
+ delete : function(id) {
+ return $http.delete('/api/todos/' + id);
+ }
+ }
+ }]);
\ No newline at end of file