Angular JS表单值不绑定到变量

时间:2015-12-16 20:24:13

标签: javascript angularjs

我有以下表格:

<form method="post" role="form" name="newCategoryForm" ng-submit="submitForm()" enctype="multipart/form-data" novalidate> 
  <div class="row">
    <div class="row">
      <div class="col s12">
        <div input-field>
          <input type="text" name="cat-name" id="cat-name"
                 ng-model="category.catname" required>
          <label>Nombre</label>
        </div>
      </div>
    </div>
    <div class="row">
      <div class="col s12">
        <div input-field>
          <textarea class="materialize-textarea" name="cat-description" id="cat-description" length="144"
                    ng-model="category.catdescription" ng-maxlength="144" required></textarea>
          <label>Descripción</label>
        </div>
      </div>
    </div>
    <div class="row">
      <div class="col s12">
        <h6>Imagen de Fondo</h6>
        <div class="file-field input-field">
          <div class="btn pink darken-2 waves-effect waves-light">
             <span>Archivo</span>
             <input type="file" name="cat-bgimg" id="cat-bgimg"
                    file-model="variable" ng-model="category.catimg">
          </div>
          <div class="file-path-wrapper">
            <input class="file-path" type="text" readonly>
          </div>
        </div>
      </div>
    </div> 
  </div>
  <button type="submit" class="btn btn-large pink darken-2 waves-effect waves-light center-button" ng-disabled="newCategoryForm.$invalid">Crear Categoría</button>
</form>

在我的控制器中我有这个:

angular.module('sccateringApp')
  .controller('newCategoryController', function (httpcalls, $scope) {
    var request = httpcalls;
    $scope.submitForm = function(){
      $scope.catinfo = $scope.category;
      console.log($scope.catinfo);
      console.log(this.category);
      console.log(newCategoryForm.category);
    }
  });

正如您所看到的,控制器记录未定义的三种方式我正在尝试打印表单的内容:

enter image description here

我对Angular很新,我很缺乏经验。我正在使用该文档作为参考:https://docs.angularjs.org/api/ng/directive/ngSubmit

知道我可能做错了吗?

0 个答案:

没有答案