控制器内部无法访问表单

时间:2015-12-19 07:11:56

标签: angularjs ionic-framework ionic

我有这个离子页面:

<ion-view view-title="Sign up for business">
  <ion-nav-bar class="bar-positive">          
    <ion-nav-back-button></ion-nav-back-button>       
    <ion-nav-buttons side="right">
      <button class="button button-icon icon ion-android-done" ng-disabled="bizzSForm.$invalid" ng-click="submitBizzForm()"></button>
    </ion-nav-buttons>
  </ion-nav-bar>
  <ion-content> 
      <form name="bizzSForm" class="css-form" ng-submit="submitSignUpForm()" novalidate>   
        <div class="list">
          <label class="item item-input">
            <i class="icon ion-person placeholder-icon"></i>
            <input type="text" placeholder="Your business or organization name" name="name" ng-model="bizzFormData.name" ng-minlength="3" ng-maxlength="50" required>
          </label>
            <div ng-show="bizzSForm.$submitted || bizzSForm.name.$touched">
                <span ng-show="bizzSForm.name.$error.required" class="form-err-blk"><i class="ion-close-round"></i>&nbsp;&nbsp;Tell us your business or organization name.</span>
            </div>

我有这个控制器代码:

  $scope.submitBizzForm = function() {
    if($scope.bizzSForm.$valid) {
      $scope.submitSignUpForm();
    }
  }

此处$scope.bizzSForm显示undefined

1 个答案:

答案 0 :(得分:0)

您可以在ngSubmit回调中传递bizzSForm,并按原样使用:

HTML

<form name="bizzSForm" class="css-form" ng-submit="submitSignUpForm(bizzSForm)" novalidate>
  <!-- content -->
</form>

的Javascript

$scope.submitBizzForm = function(form) {
    if(form.$valid) {
      $scope.submitSignUpForm();
    }
};