AngularJS JQuery Ajax form submission Equivalent

后端 未结 1 1201
终归单人心
终归单人心 2020-12-22 04:10

Lately I have jumped into angularjs and its wonderful so far. I have been sending AJAX requests through $http service. Today I was shocked to find that there is no simple wa

相关标签:
1条回答
  • 2020-12-22 04:49

    There is an equivalent in angular, here is a link to a jsfiddle with an example implementation: http://jsfiddle.net/dmcquillan314/boo5tn62/

    The function on line 11 is an example of how to send a request to a rest api:

    $scope.sendToResource = function() {}
    

    To enable this feature just change the function in the directive to point to this factory and it will send a request to the api url configured in the factory.

    In order to test this with an api you'll have to change the factory to match your server

    here are some links to relevant documentation:

    https://docs.angularjs.org/api/ngResource/service/$resource

    https://docs.angularjs.org/api/ng/directive/ngSubmit

    https://docs.angularjs.org/api/auto/service/$provide

    Let me know if anything is unclear or you require any further explanation. Hopefully this should help you get started.

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