2016-06-14 7 views
1

親のngFormステータスを更新しておくのに問題があります。すべての子供がきれいになって "元気"になったら "Pristine"に設定する必要がありますが、自動的には起こっていないようです。私は間違っhttp://plnkr.co/edit/vCX7ltOb8fgl3fkEpvzy?p=preview親ngForm子フォームに基づく汚れたステータス

<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> 

は、私はより良い問題を説明するためにここにplunkを作成しましたか?私は、外部モジュールを使用してソリューションを見つけました...私は可能な限り少ないコードで解決したいと思います(おそらく指示?)。

+1

私はあなたを見つけたと思います自分の答えは、 'angle-input-modified'である!解決策を追加して回答としてマークし、コミュニティと共有してください。 – gsubiran

答えて

0

私は "角度入力修飾" と私自身の答えはここに更新plunkですが見つかりました:http://plnkr.co/edit/vCX7ltOb8fgl3fkEpvzy?p=preview

HTML:

<!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> 

JS:

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(); 
    } 

}); 
関連する問題