So you want an angular if else class something like this:
1 2 3 |
class="{test: obj.value1 == 'someothervalue'}" |
or
1 2 3 |
ng-class="{test: obj.value1 == 'someothervalue' || obj.value2 == 'somethingelse'} |
If you want to include a scope variable as a class, you can’t use ng-class. So with Bootstrap classes you could do something like this to get an error class appear if your login form comes back with incorrect password (or such) and a success class if it’s a correct login.
Login controller.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
$scope.formMessage = ""; /* alert-success, alert-warning, alert-info, alert-danger */ $scope.formMessageClass = "alert-info"; $scope.$on('$auth:loginSuccess', function (event, data) { console.log("LoginController:",event,data); $scope.formMessageClass = "alert-success"; $scope.formMessage = "Login success."; }); $scope.$on('$auth:loginFailure', function (event, data) { console.log("LoginController:",event,data); $scope.formMessageClass = "alert-danger"; $scope.formMessage = "Username or password incorrect."; }); |
HTML
1 2 3 4 |
<!-- Form error/success messgaes --> <div class="alert form-messages {{formMessageClass}} alert-dismissable" ng-show="formMessage">{{ formMessage }}</div> |
Do you mind to share the source code with us?
Hi mate yeah the source code is here: https://github.com/sdeering/angular-seed/blob/master/app/views/login.html
Check to this link. http://goo.gl/rfPHqW
Awesome post!! It helpful for me.
It might help you!!
http://www.code-sample.com/2014/10/ng-if-else-in-angularjs.html
Good one @disqus_ONq5L9UlcT:disqus !!! keep it, Thanks.
Thank you very much!!
Good Article , Have you more ng-if else articles. I found one ng-if articles here. http://goo.gl/wQ30uf
It’s helpful post. Have a detail example about ng-class if-else at http://angularjsaz.blogspot.com/2015/09/ng-class-if-example.html
Good Article on Angularjs . It is possible show alert css class without use of angularjs expression . Means define something into css class ? I read many article on ng if else , one good article here – http://goo.gl/bZGU6t
Have other a good way that we can make a function to manage return class with condition
http://angularjsaz.blogspot.com/2015/09/ng-class-if-example.html