<\/script>')

How to apply changes in angularjs (ng-show)?

I have a 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 set to true, but the div with the error message does not appear. How to show it?

+6
source share
2 answers

Angular does not check the value of your invalid_credentials variable. Using a function as an argument to ng-show should work.

+8
source

The accepted answer will work ... However, what you really need to do is use $ scope. $ apply

 utApp.controller "SessionController", ($scope, $cookieStore, ClientService) -> $scope.login = -> if something $scope.$apply (s) -> s.invalid_credentials = true 

Typically, when updating the scope and it does not update the user interface ... because you need to use $ apply .

+2
source

Source: https://habr.com/ru/post/927255/


All Articles