Method 1. Use the function in $ scope configured by your controller.
So, in order to better understand your problem, you wanted to show a message if any field in your form was invalid and $ dirty ...
Add a controller method:
app.controller('MainCtrl', function($scope) { $scope.anyDirtyAndInvalid = function (form){ for(var prop in form) { if(form.hasOwnProperty(prop)) { if(form[prop].$dirty && form[prop].$invalid) { return true; } } } return false; }; });
and in your HTML:
<span ng-show="anyDirtyAndInvalid(submit_entry_form);">Error!</span>
Here is a demo plunker
Now all of the above, if someone entered the data in your form and did not complete it, the form itself is invalid. So I'm not sure if this is the best usability. But it should work.
Method 2: use a filter! (Recommended)
Now I recommend a filter for this kind of thing ...
The following filter performs the same actions as above, but is better suited for Angular, IMO. Also plunk.
app.filter('anyInvalidDirtyFields', function () { return function(form) { for(var prop in form) { if(form.hasOwnProperty(prop)) { if(form[prop].$invalid && form[prop].$dirty) { return true; } } } return false; }; });
<span ng-show="submit_entry_form | anyInvalidDirtyFields">Error!</span>
Ben lesh
source share