phan ngoc phan ngoc - 1 year ago 92
AngularJS Question

How to change function in ng-submit angularjs

The situation occur when i want to convert form create into update form, so i need create() in ng-submit change to update(). How do i can make it ? .Concrete example:

<form name="articleForm" class="form-horizontal" ng-submit="create()" novalidate>


<form name="articleForm" class="form-horizontal" ng-submit="update()" novalidate>

Thank you !

Answer Source

What about :

<form name="articleForm" class="form-horizontal" ng-submit="submit()" novalidate>

and then have something like this in your controller :

$scope.isNewUser = typeof $ === 'undefined';

function create() {...}
function update() {...}

$scope.submit = function () {
    $scope.isNewUser ? create() : update();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download