I am building a phone directory application, where I have made a Log in system. When user successfully logs in, the login button will hide. Maybe I am doing it in a wrong way.
//html code is
<ul class="nav navbar-nav pull-right" ng-controller="chklogin as a" ng-switch on="a.logedin" >
<li class="active"><a href="#/Home">Home</a></li>
<li ng-switch-default><a href="#/login" >Login {{a.logedin;}}</a></li>
<li ng-switch-when="true"><a href="#/Dashboard">Dashboard</a></li>
<li ng-switch-when="true"><a href="#" ng-click="a.logout();">Logout</a></li>
</ul>
//controller
myApp.controller("chklogin", function() {
this.logedin='false';
$.ajax({
url: "process/chklogin.php",
type: "post"
}).done(function(res) {
if (res == 'true') {
return this.logedin='true';
}
else
{
return this.logedin='false';
}
});
this.logout= function(){
$.ajax({
url: "process/logout.php",
type: "post"
}).done(function(res) {
window.location="#/login";
});
}
});
- Now tell me what am I doing wrong and what should I do?
- What should I learn for this and where I can find it?
- Tell me how the controller updates the view when it logs in or logs out.