Search code examples
javascriptangularjsng-file-upload

Submit a form with POST action using angular


I am trying to submit a form using angular1 but when I click submit I can't see the call being made to /create in Network tab of Chrome Dev tool.

My app.js is:

app.controller('MyCtrl', ['$scope', 'Upload', '$timeout', function ($scope, Upload, $http, $timeout) {
    $scope.loaderHidden = true;

    $scope.csvurls = function() {
        alert("here");
        $http({
            method : 'POST',
            url : '/create'
        })
    }
    ....
}]);

My form is below:

    <form class="form-inline" ng-submit="csvurls()">
      <input type="text" id="inlineFormInput">
      <button type="submit" class="btn btn-primary">Submit</button>
    </form>

When I click submit I can see the alert however, I don't think the call to /create is being initiated. I don't see any errors in the log either.

FWIW I am also using ng-file-upload in my application.


Solution

  • You need to add $http as a dependency like this:

    app.controller('MyCtrl', ['$scope', 'Upload', '$http', '$timeout', function ($scope, Upload, $http, $timeout) {