0

I know how to do one off validations in angular. What I am looking to do is to display a warning at the top of the page if any errors exist in the below forms that were trying to submit. How do I accomplish this?

Is there a form.$errors? For if any error occurs on the page?

So can I do something like this?

<div id="errorInfoHeader" ng-show="formName.$errors"> 

2 Answers 2

4

Yes, you're on the right track:

formName.$invalid

is what you're looking for.

<div id="errorInfoHeader" ng-show="formName.$invalid">

See this plunkr that demonstrates what you're trying to do: http://plnkr.co/edit/9Ny58FY9rv74sxXryKmh?p=preview

Sign up to request clarification or add additional context in comments.

3 Comments

Ok, question this sort of seems to work, but only after the form is declared. If the div tag is before the form. It doesn't execute. So how do I get it to execute.
In your controller, you can bind formName.$invalid to another variable on the scope. Then use that variable to show/hide your errorInfoHeader.
Found it I had a different controller declared in between
1

You can use $valid like this:

<div id="errorInfoHeader" ng-show="formName.$valid">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.