title: Creating a transaction in Angular JS
body: <p>I have a function as <code>$scope.submit()</code> in my <code>angular js</code> application. Following is the code.</p>
  
  <pre><code>scope.submit = function () {
      var reqDate = dateFilter(scope.first.date, scope.df);
      this.formData.locale = scope.optlang.code;
      this.formData.active = this.formData.active || false;
      this.formData.dateFormat = scope.df;
      this.formData.activationDate = reqDate;
  
      if (routeParams.groupId) {
          this.formData.groupId = routeParams.groupId;
      }
  
      if (routeParams.officeId) {
          this.formData.officeId = routeParams.officeId;
      }
  
      if (scope.first.submitondate) {
          reqDate = dateFilter(scope.first.submitondate, scope.df);
          this.formData.submittedOnDate = reqDate;
      }
  
      if (scope.first.dateOfBirth) {
          this.formData.dateOfBirth = dateFilter(scope.first.dateOfBirth, scope.df);
      }
  
      if (!scope.opensavingsproduct) {
          this.formData.savingsProductId = null;
      }
      resourceFactory.clientResource.save(this.formData, function (data) {
          scope.newid = data.clientId;
          return  scope.newid
      });
      resourceFactory.clientIdenfierResource.save({
          clientId: scope.newid
      }, this.formData2, function (data) {
          location.path('/viewclient/' + data.clientId);
      });
  };
  </code></pre>
  
  <p>The first <code>resourceFactory.clientResource.save</code> creates a client and pass the client id. The second <code>resourceFactory.clientIdenfierResource.save</code> creates the identifier like passport number and check if another client with the same passport number exists.</p>
  
  <p>i wanted to roll back first one if the second doesn't finish. Like if we have a transaction,</p>
  
  <ul>
  <li>save 1 = first transaction</li>
  <li>save 2 = second transaction</li>
  </ul>
  
  <p>if save 2 has finished then commit rest of the transaction. How can i do it in <code>angular</code>. Please advise.</p>