0

When I'm trying to create a new task, nothing happens and no request being sent. Why is that so? How can I debug the issue?

Here's how it looks

Here's $scope.add function

 var app = angular.module('Tasks', ['ngResource', 'xeditable']);

  app.factory('Task', [
    '$resource', function($resource) {
      return $resource('/tasks/:id', {
        id: '@id'
      }, {
        update: {
          method: 'PUT'
        }
      });
    }
  ]);

  this.TasksCtrl = [
    '$scope', 'Task', function($scope, Task) {

      $scope.add = function() {
        var task;
        task = Task.create($scope.newTask);
        $scope.tasks.push(task);
        return $scope.newTask = {};
      };
  ];

Here's my html part.

<div ng-controller='TasksCtrl' class='tasks-container'>
  <form ng-submit='add()'>
    <input type='text' ng-model='newTask.title'/>
    <button type='button' class='btn btn-default btn-sm'>
      <span class='glyphicon glyphicon-plus'></span> Add
    </button>
  </form>
3
  • you're not adding a create-function you're adding a update-function to your resource class. Try task = Task.update($scope.newTask); instead Commented Aug 24, 2015 at 7:17
  • You're right. But how can update have something to do with POST request? I'm confused Commented Aug 24, 2015 at 8:07
  • not exactly sure what you mean. You're the one declaring the update-function as a PUT request in your factory Task Commented Aug 24, 2015 at 8:22

1 Answer 1

1

Your form has an ng-submit directive that gets called when the form is submitted. But you don't have a submit button on your form (<button type='button'> does not submit the form). Change this:

<button type='submit' class='btn btn-default btn-sm'>

and it should work.

Sign up to request clarification or add additional context in comments.

1 Comment

It helped partially. Thanks anyway. Now I have another problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.