如何从Angular-Payments获取formData

时间:2015-03-19 23:49:28

标签: javascript angularjs angular-ngmodel

我正在使用拦截表单数据的Angular-Payments并将其提交给Stripe。这很好用,但是,我不确定如何在发送到条带后访问表单数据。例如,我的表单有数量字段,我想访问,但我不知道如何...

以下是我正在做的HTML

<form stripe-form="handleStripe" role="form" ng-if="authenticated" name="takeMoneyForm" ng-submit="takeMoney(takeMoneyForm, model)">
      <input type="text" name="card_number" ng-model="number" payments-validate="card" payments-format="card" payments-type-model="type" ng-class="takeMoneyForm.number.$card.type">
       <input type="text"  name="card_cvc" ng-model="cvc" payments-validate="cvc" payments-format="cvc" payments-type-model="type">
      <input type="text" nam="card_expiry" ng-model="expiry" payments-validate="expiry" payments-format="expiry">
      <input type="text" ng-model="quantity"/>
      <button class='form-control  submit-button btn btn-majoo' type='submit'>Pay »</button>
</form>

JS

  $scope.takeMoney = function(formData, model){
    $scope.handleStripe = function(status, response){
      if(response.error) {
        // there was an error. Fix it.
        alert("Error happened")
      } else {
        var dataModel = {
          email: model.email,
          profile: {
            stripe_token: response.id,
            stripe_id: model.profile.stripe_id
            //here I would like to get access to the quantity from the form
          }
        }
        djangoAuth.takeMoney(dataModel)
        $scope.complete = true;
      }
    }
  }

我觉得这应该很简单,但我对Angular很新,似乎无法解决这个问题。

1 个答案:

答案 0 :(得分:0)

因为您使用ng-model,这些字段的值应该在该表单的范围内(如scope.number中所示) 如果它们不可访问,则可能是以下两种情况之一:

1)Angular Payments在提交

后清除ng模型

2)您正试图从不同的范围访问它。