0

I have to show an error msg on unique validation check on my html page. I have set error msg on $scope variable. But I am not getting how to display error msg on html page.

This is my controller code where I am setting error msg like:

$scope.error=="Name already in use"

This is my html page where I want to show error message:

<!--I am showing msg like this but the poblem is when the page is being loaded {} comes. -->
<span class="error" ng-show="error"> {{error}}</span>

How to show error msg only when some error msg comes. Please suggest some way for this.

enter image description here

3
  • Do you mean $scope.error="Name already in use" ? Commented Jun 24, 2015 at 9:25
  • Because $scope.error=="Name already in use" does not set $scope.error Commented Jun 24, 2015 at 9:27
  • I have set an error msg like this. I want to show this error msg if validation fails Commented Jun 24, 2015 at 9:34

2 Answers 2

2

from docs

The ngCloak directive is used to prevent the Angular html template from being briefly displayed by the browser in its raw (uncompiled) form while your application is loading. Use this directive to avoid the undesirable flicker effect caused by the html template display.

<span class="error" ng-show="error" ng-cloak> {{error}}</span>

or i guess you have initialized $scope.error='{}' somewhere,remove it if that's the case.

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

3 Comments

I have tried your solution but still am getting blank braces {} when there is no error msg. Adding a screenshot for your refrence
@FatemaRangwala have you initialised your $scope.error somewhere?
there is no error on console, If have only set $scope.error=undefined on change event of the field. I haven't initialized it anywhere.
2

try < span ng-bind="error" >< /span >"

In the case when there is no error you need to reassign a null or an empty value to the error variable of the scope.

2 Comments

koustubh is right. <span ng-bind="error">Default Message</span> is the correct way to handle the flicker loading.
In addition to ng-bind, I recommend including ng-if="error"

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.