相关疑难解决方法(0)

为什么在检查$ pristine或$ setDirty()时在ng-include中形成undefined?

当我单击"检查"按钮时,以下代码抛出错误"TypeError:无法读取属性'$ pristine'的undefined".

app.controller('MainCtrl', function($scope) {
  // other stuff
})

.controller('Ctrl2', function($scope) {
  $scope.product = {description:'pump'};
  $scope.output = 'unknown';
  // uncomment to avoid undefined error, still can't see $pristine
  // $scope.formHolder = {};
  $scope.checkForm = function() {
    $scope.descriptionTest = $scope.product.description;
    if ($scope.formHolder.productForm.$pristine) {
      $scope.output = 'yes';
    }
    if ($scope.formHolder.productForm.$dirty) {
      $scope.output = 'no' 
    }
  }
});
Run Code Online (Sandbox Code Playgroud)

HTML

  <body ng-controller="MainCtrl">
    <div >
      <ng-include ng-controller="Ctrl2" src="'myForm.html'"></ng-include>
    </div>
  </body>
Run Code Online (Sandbox Code Playgroud)

myForm.html

<form name="productForm" novalidate>
  <h2>myForm</h2>
  description: <input type="text" name="description" ng-model="product.description"/>
  <br>
  <button ng-click="checkForm()">Check Form</button>
  <br> …
Run Code Online (Sandbox Code Playgroud)

angularjs angularjs-ng-include

26
推荐指数
1
解决办法
1万
查看次数

我可以在其他表单标签中嵌套表单标签吗?

我可以<form>在另一个<form>标签内放置标签吗?

例如:

<form>
  <form>
  </form>
</form>
Run Code Online (Sandbox Code Playgroud)

html forms

12
推荐指数
1
解决办法
1万
查看次数

标签 统计

angularjs ×1

angularjs-ng-include ×1

forms ×1

html ×1