我正在使用 Auth0,它允许我在登录完成后检索用户个人资料信息,如下所示:
<span>Name is {{auth.profile.nickname}}</span>
// UserInfoCtrl.js
function UserInfoCtrl($scope, auth) {
$scope.auth = auth;
}
我想做的是使用 ng-show 和 ng-hide 仅在用户登录后显示内容。其他人是如何做到这一点的?我在我的 UserInfoCtrl.js 中设想了类似条件语句的东西,例如:
if($scope.auth !== null) {
$scope.loggedin
}
更新:根据关于 falselys 的评论和 $scope.auth 提供了一些值(value),也许最好将某些东西绑定(bind)到登录 Controller 。有什么想法吗?
// Login and logout functionality
pfcControllers.controller('loginCtrl', ['$scope', 'auth', '$location', 'store', function ($scope, auth, $location, store) {
$scope.login = function () {
auth.signin({}, function (profile, token) {
store.set('profile', profile);
store.set('token', token);
$location.path("/");
}, function (error) {
console.log("There was an error logging in", error);
});
}
$scope.logout = function () {
auth.signout();
store.remove('profile');
store.remove('token');
$location.path('/login');
}
}]);
最佳答案
如果 $scope.auth
只有在用户登录时才有值,你可以这样做:
<span ng-show="auth">Name is {{auth.profile.nickname}}</span>
这样,如果定义了 auth
,您将只会看到 span
。
关于javascript - angularjs ng-show/ng-hide 在用户登录后显示内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27904596/