Getting form controls from FormController

前端 未结 4 1648
清歌不尽
清歌不尽 2020-12-30 22:48

I need a way to loop through the registered controls of an AngularJS form. Essentially, I\'m trying to get all the $dirty controls, but there\'s no array of the controls (t

4条回答
  •  太阳男子
    2020-12-30 23:15

    try simply with from within your controller:

    $scope.checkForm = function(myFormName){
         console.log(myFormName.$invalid);
    }
    

    UPDATE:



    app.controller('MyController',function($scope){ $scope.user = {}; $scope.update = function (form){ var editedFields = []; angular.forEach($scope.user, function(value, key){ if(form[key].$dirty){ this.push(key + ': ' + value); } }, editedFields); console.log(editedFields); } });

提交回复
热议问题