form
入力を属性付きのに入れ、入力にname
属性を与えると、入力のプロパティname
にもアクセスできます。$pristine
<div ng-controller="MyController">
<form name="myForm">
<input type="text" name="first" ng-model="firstName">
<input type="text" name="last" ng-model="lastName">
</form>
</div>
app.controller('MyController', function($scope) {
// Here you have access to the inputs' `$pristine` property
console.log($scope.myForm.first.$pristine);
console.log($scope.myForm.last.$pristine);
});
を使用して、フィールドが変更された$scope.myForm.$pristine
かどうか$pristine
を確認したり、フォームの各入力のプロパティのプロパティを使用して、その入力が変更されたかどうかを確認したりできます。オブジェクトを反復処理することもできmyForm
ます (入力フィールド以外のオブジェクトには、キーの前に が付きます$
)。
angular.forEach($scope.myForm, function(value, key) {
if(key[0] == '$') return;
console.log(key, value.$pristine)
});
// first, true
// last, false