Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app.factory('Tarefa',
- function($resource){
- return $resource('https://todowebservice.herokuapp.com/api/todos/:id');
- });
- app.controller('tarefaController',
- function($scope, $routeParams, Tarefa){
- if($routeParams.id){
- Tarefa.get(
- {id: $routeParams.id},
- function(tarefa){
- $scope.tarefa = tarefa;
- },
- function(erro){
- console.log(erro);
- });
- }else{
- $scope.tarefa = new Tarefa();
- }
- $scope.salva = function(){
- $scope.tarefa.$save()
- .then(function(){
- $scope.tarefa = new Tarefa();
- })
- .catch(function(erro){
- console.log(erro);
- });
- };
- });
- <form ng-submit="salva()">
- <div class="form-group">
- <label for="description">Descrição</label>
- <input type="text" name="description" id="description" class="form-control" required ng-model="tarefa.description" />
- </div>
- <div class="form-group">
- <label for="done">Realizado</label>
- <div class="input-group">
- <input type="checkbox" class="form-control" id="done" name="done"
- ng-model="tarefa.done" />
- </div>
- </div>
- <div class="form-group">
- <label for="createdAt">Criado em</label>
- <input type="text" name="createdAt" id="createdAt" class="form-control" ng-model="tarefa.createdAt" />
- </div>
- <div>
- <button type="submit" class="btn btn-primary">
- Salvar
- </button>
- </div>
- </form>
- {…}config: Object { method: "POST", transformRequest: (1) […], url: "https://todowebservice.herokuapp.com/api/todos", … }data: Object { code: 11000, index: 0, errmsg: "E11000 duplicate key error index: todoweb.todos.$_id_ dup key: { : ObjectId('5ab30cbded34a40011eb7be6') }", … }headers: function headersGetter()status: 400statusText: "Bad Request"__proto__: Object { … } tarefaController.js:23:9
Add Comment
Please, Sign In to add comment