Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 基于子窗体的父窗体脏状态_Angularjs_Angularjs Ng Form - Fatal编程技术网

Angularjs 基于子窗体的父窗体脏状态

Angularjs 基于子窗体的父窗体脏状态,angularjs,angularjs-ng-form,Angularjs,Angularjs Ng Form,我在试图更新我的父母ngForm状态时遇到了一些问题;当所有的孩子都被清洗干净后,它应该被设置为“原始”,并将他们自己设置为“原始”。。。但这似乎不是自动发生的 我在这里创建了一个plunk来更好地解释这个问题: parentForm1.dirty:{{parentForm1.$dirty} childForm1.dirty:{{childForm1.$dirty} 清净 childForm2.dirty:{{childForm2.$dirty} 清净 我错在哪里?我找到了使用外部模

我在试图更新我的父母ngForm状态时遇到了一些问题;当所有的孩子都被清洗干净后,它应该被设置为“原始”,并将他们自己设置为“原始”。。。但这似乎不是自动发生的

我在这里创建了一个plunk来更好地解释这个问题:


parentForm1.dirty:{{parentForm1.$dirty}
childForm1.dirty:{{childForm1.$dirty}


清净 childForm2.dirty:{{childForm2.$dirty}

清净

我错在哪里?我找到了使用外部模块的解决方案。。。我想用尽可能少的代码(也许是指令?)来解决这个问题。

我用“角度输入修改”找到了自己的答案,下面是更新后的plunk:

HTML:


我用“角度输入修改”找到了我自己的答案这里是更新后的plunk:

HTML:


我想你找到了自己的答案,修改了“角度输入”!请添加解决方案并将其标记为已回答,以便与社区共享。我认为您找到了自己的答案,即“角度输入已修改”!请添加解决方案并将其标记为已回答,以便与社区共享。
<body ng-controller="MainCtrl">

    <div ng-form="parentForm1" class="parent-form">
      parentForm1.dirty: <b>{{parentForm1.$dirty}}</b>

      <form name="childForm1" class="child-form" novalidate>
        childForm1.dirty: <b>{{childForm1.$dirty}}</b>
        <br/>
        <input type="text" ng-model="field1">
        <br/>
        <button ng-click="reset1()">Clean and setPristine</button>
      </form>

      <form name="childForm2" class="child-form" novalidate>
        childForm2.dirty: <b>{{childForm2.$dirty}}</b>
        <br/>
        <input type="text" ng-model="field2">
        <br/>
        <button ng-click="reset2()">Clean and setPristine</button>
      </form>

    </div>

  </body>
<!DOCTYPE html>
<html ng-app="test">

<head>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
  <script src="//rawgit.com/betsol/angular-input-modified/master/dist/angular-input-modified.js"></script>
  <script src="script.js"></script>
  <link rel="stylesheet" href="style.css" />
</head>

<body ng-controller="MainCtrl">

  <div ng-form="parentForm1" class="parent-form">
    parentForm1.dirty: <b>{{parentForm1.$dirty}}</b>
    <br/>
    parentForm1.modified: <b>{{parentForm1.modified}}</b>

    <form name="childForm1" class="child-form" novalidate>
      childForm1.dirty: <b>{{childForm1.$dirty}}</b>
      <br/>
      <input type="text" ng-model="field1">
      <br/>
      <button ng-click="reset1()">Clean and setPristine</button>
    </form>

    <form name="childForm2" class="child-form" novalidate>
      childForm2.dirty: <b>{{childForm2.$dirty}}</b>
      <br/>
      <input type="text" ng-model="field2">
      <br/>
      <button ng-click="reset2()">Clean and setPristine</button>
    </form>

  </div>

  <form name="exChildForm1" class="child-form" novalidate>
    exChildForm1.dirty: <b>{{exChildForm1.$dirty}}</b>
    <br/>
    <input type="text" ng-model="exfield1">
    <br/>
    <button ng-click="exreset1()">Clean and setPristine</button>
  </form>

</body>

</html>
var app = angular.module('test', ['ngInputModified']);

app.controller('MainCtrl', function($scope) {

  $scope.reset1 = function() {
    $scope.field1 = null;
    $scope.childForm1.$setPristine();
  }

  $scope.reset2 = function() {
    $scope.field2 = null;
    $scope.childForm2.$setPristine();
  }

  $scope.exreset1 = function() {
    $scope.exfield1 = null;
    $scope.exChildForm1.$setPristine();
  }

});