I have form
<form ng-controller="SessionController" name="login_form">
<div class="hide" ng-show='invalid_credentials'>Invalid email/pass</div>
<input type="submit" value="Login" ng-click='login()'>
</form>
Controller:
utApp.controller('SessionController', ($scope, $cookieStore, ClientService) ->
$scope.login = ->
...
if something
$scope.invalid_credentials = true
return
on some conditions $scope.invalid_credentials
is getting set to true, but div with error message is not being shown. How to show it?
Definition and UsageThe ng-change event is triggered at every change in the value. It will not wait until all changes are made, or when the input field loses focus. The ng-change event is only triggered if there is a actual change in the input value, and not if the change was made from a JavaScript.
The ng-show Directive in AngluarJS is used to show or hide the specified HTML element. If the given expression in the ng-show attribute is true then the HTML element will display otherwise it hides the HTML element. It is supported by all HTML elements.
The ng-change Directive in AngularJS is used whenever the value of an input element changes. The expression is evaluated immediately whenever there is a change in the input value. It requires an ng-model directive to be present. It is triggered whenever there is any single change in the input.
Absolutely not. First of all, the two directives can trip over each other( see this JSFiddle, as provided by Joel Skrepnek), and is generally just bad design.
Angular doesn't re-check the value of your invalid_credentials
variable. Using a function as your ng-show
argument should work.
The accepted answer will work... However, what you really needed to do is use $scope.$apply
utApp.controller "SessionController", ($scope, $cookieStore, ClientService) ->
$scope.login = ->
if something
$scope.$apply (s) ->
s.invalid_credentials = true
Generally, when you update the scope, and it doesn't update the UI... it's because you need to use $apply.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With