Answer the question
In order to leave comments, you need to log in
How to organize a function call?
Good afternoon.
AngularJs project. There are two controllers and a factory.
the first controller calls a method from the factory to access the database.
function navbarCtrl($scope, Auth) {
vm = this
vm.login = async function () {
console.log(Auth.getUsername())
const authToken = await Auth.login(vm.credential.username, vm.credential.password)
}
vm.credential = {
username: null,
password: null
}
}
auth.getUsername = function () {
if (auth.user && auth.user.username) {
return auth.user.username;
} else {
return null
}
}
<ul class="nav navbar-nav navbar-right" ng-controller='statusCtrl as sc' >
<li ><a href="#/login" ng-hide='sc.getUserName()'>Sing in </a></li>
<li ng-show='sc.getUserName()'><a href="#/login">{{sc.getUserName()}} logout</a></li>
</ul>
function statusCtrl($scope, Auth) {
vm = this
vm.getUserName = function () {
return Auth.getUsername()
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question