Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access form element in ng-Submit

Tags:

angularjs

I am new to angular js and I am struck with accessing the form element in ng-submit function. My intention is to set the action attribute dynamically and submit the form rather using jquery selector and setting the action attribute.

<div ng-app="MyApp">
    <form name="myForm" ng-controller="myController" 
     ng-submit="SubmitFunction(myForm)">
        <input type="submit" value="Submit" />            
    </form>
</div>

JS:
    var myApp = angular.module("MyApp",[]);
    myApp.controller("myController", ["$scope", function ($scope) {
        $scope.SubmitFunction = function (formElement) {
            //Set action attribute ???
           //Submit the form ????
        };           
    }]);
like image 738
Venkat Avatar asked Jan 17 '14 21:01

Venkat


1 Answers

Thanks for ur help. Finally found a solution.

<div ng-app="MyApp">
    <form name="myForm" ng-controller="myController" 
    ng-submit="SubmitFunction($event)">
        <input type="submit" value="Submit" />            
   </form>
</div>

JS:
var myApp = angular.module("MyApp",[]);
myApp.controller("myController", ["$scope", function ($scope) {
    $scope.SubmitFunction = function (e) {
        var formElement = angular.element(e.target);
        formElement.attr("action", actionLink);
        formElement.submit();
    };           
}]);
like image 92
Venkat Avatar answered Nov 03 '22 04:11

Venkat