1

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>

to

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

Thank you !

phan ngoc
  • 191
  • 3
  • 14

5 Answers5

2

Just use a ternary with one variable defined in the $scope:

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

in your controler define:

$scope.isCreation = true;

and change it to false when you want update() to be triggered

Vi100
  • 4,080
  • 1
  • 27
  • 42
0

Either you could use ng-if determine which one is needed, or use the same function and check inside the function if you are in create or update mode. You could also use directives and pass the function to your directive, depending how you want to use this form, because that is not perfectly clear for me.

0

What about :

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

and then have something like this in your controller :

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

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

$scope.submit = function () {
    $scope.isNewUser ? create() : update();
}
Salem Ouerdani
  • 7,596
  • 3
  • 40
  • 52
0

define $scope.isCreate=true;// true for create, false for update in Angular Controller and at form

<form novalidate ng-submit="isCreate?create():update()">
Shiva Kumar
  • 242
  • 1
  • 4
  • 9
0

Little Later But Useful

      <form class="form-horizontal"  name="BannerForm"  
       ng-submit="call(submitOption)" novalidate>


 //**For MultiSubmit
   $scope.call = function(expr) {
    return $scope.$eval(expr);
  };

//For InsertNew
    $scope.InsertData= function(){
    $scope.submitOption="add()";
    }


//For UpDate
    $scope.UpdateData= function(){
    $scope.submitOption="update()";
    }
Pandi_Snkl
  • 476
  • 5
  • 16