-
Notifications
You must be signed in to change notification settings - Fork 26
Open
Description
Hi guys,
first of all: thanks a lot for this cool package.
I am just starting out with angular and I could really use some good examples on how to use this resource.
- How do I register it as a factory?
- How do I do a simple INSERT when listening to a form (for example add a new todo item to a todo-list).
- How do I do a eimple UPDATE (for example when editing an existing todo item to a todo-list).
Could somebody help me out?
For question 1) I think I have found the way to do it::
// services.js
var todoServices = angular.module('todoServices', ['djangoRESTResources'])
.factory('Todo', function (djResource) {
return djResource('/api/todos/:todoId/', {todoId:'@id'});
}
);Right now I am stuck with question 2). How do I insert a new item? This is my current code (NOT working):
<form ng-submit="TodoListCtrl.addTodo(todo)" novalidate>
<div class="form-group">
<label for="exampleInputEmail1">Description</label>
<input ng-model="todo.description" id="todoDescription" type="text" class="form-control" placeholder="Todo">
</div>
<div class="checkbox">
<label>
<input ng-model="todo.is_done" id="todoIsDone" type="checkbox"> ist done?
</label>
</div>
<button ng-click="add(todo)" type="submit" class="btn btn-default">submit</button>
</form>// controllers.js
todoControllers.controller('TodoListCtrl', ['$scope', 'Todo',
function ($scope, Todo) {
$scope.todos = Todo.query();
$scope.add = function(todo) {
var newTodo = new Todo({description:todo.description, is_done:todo.is_done});
newTodo.$save();
}
}
]);Any ideas how to do this?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels