user6039980 user6039980 - 6 months ago 18
AngularJS Question

AngularJS: conditional binding is not working

I'm trying to validate user's input onto the email address field inside a form, and I used to create a span in which the error message gets generated in the case of typing an invalid value. This is the span HTML code:

<div ng-app="app" ng-controller='signupCtrl'>
<span style="padding: 2px 0 2px 16px; color: red;" ng-if="check_mail()">Please type a valid email address</span>
</div>


I used the
ng-if
tag for conditionally binding the error message


Please type a valid email address


, and
check_mail()
function for checking the value from a
signupCtrl
controller.

The
check_mail
function works fine as expected. However the error message was never displayed though. So is there anything wrong on my HTML code? How is it possible to solve this problem?

Thanks.

Answer

does the function check_mail() returns true if the mail is invalid? if it doesnt then you may want to try

<div ng-app="app" ng-controller='signupCtrl'>
      <span style="padding: 2px 0 2px 16px; color: red;" ng-   if="!check_mail()">Please type a valid email address</span>
      </div>