Angular.js submit form old way

后端 未结 3 540
逝去的感伤
逝去的感伤 2020-12-09 02:42

I\'m migrating an old html page from jQuery to Angular, and it contains some old-school forms with . When I enriched my pages with

相关标签:
3条回答
  • 2020-12-09 03:19

    Going off of the docs: http://docs.angularjs.org/api/ng.directive:form

    Angular's philosophy is to minimize data and page reloads, so they don't like "old school forms", but you can get around it by using an action attribute in the form.

    Angular is designed with single page applications in mind and avoiding full page reloads as that is going to take longer to do. By using the ngSubmit directive, you can define a function to send over the form data to the server and get a response back much quicker than a full page reload. Bytes instead of Kilobytes.

    0 讨论(0)
  • 2020-12-09 03:24

    I've done this. I'm pretty sure I was using jquery to submit the form, but you could probably do it with plain old javascript.

    One of the comments on the angular form page suggests this:

    <input onclick="javascript:$(this).parent().submit();" type="submit" value="">
    

    http://docs.angularjs.org/api/ng.directive:form

    0 讨论(0)
  • 2020-12-09 03:29
    • Use a non-empty action attribute to make Angular submit the form
    • Fill action attribute with current location (using angular)

    In your controller:

    $scope.location = $window.location.href
    

    In your HTML:

    <form action="{{location}}">
    

    See the plunkr demo.

    0 讨论(0)
提交回复
热议问题