Permalink
Browse files

AngularJS Create

  • Loading branch information...
1 parent 2aff6fe commit 46dd14023e2d9eff72d1366dbba9c9c8c872e07b @amejiarosario committed Oct 3, 2014
Showing with 11 additions and 0 deletions.
  1. +11 −0 views/index.ejs
View
@@ -23,6 +23,7 @@
<a href="#/{{$index}}">{{todo.name}}</a>
</li>
</ul>
+ New task <input type="text" ng-model="newTodo"><button ng-click="save()">Create</button>
</script>
<script type="text/ng-template" id="/todoDetails.html">
@@ -50,6 +51,16 @@
.controller('TodoController', ['$scope', 'Todos', function ($scope, Todos) {
$scope.todos = Todos.query();
+
+ $scope.save = function(){
+ if(!$scope.newTodo || $scope.newTodo.length < 1) return;
+ var todo = new Todos({ name: $scope.newTodo, completed: false });
+
+ todo.$save(function(){
+ $scope.todos.push(todo);
+ $scope.newTodo = ''; // clear textbox
+ });
+ }
}])
.controller('TodoDetailCtrl', ['$scope', '$routeParams', 'Todos', function ($scope, $routeParams, Todos) {

0 comments on commit 46dd140

Please sign in to comment.