Javascript angularjs ng show/ng hide可在用户登录后显示内容
我使用的是Auth0,它允许我在登录完成后检索用户配置文件信息,如下所示:Javascript angularjs ng show/ng hide可在用户登录后显示内容,javascript,angularjs,Javascript,Angularjs,我使用的是Auth0,它允许我在登录完成后检索用户配置文件信息,如下所示: <span>Name is {{auth.profile.nickname}}</span> // UserInfoCtrl.js function UserInfoCtrl($scope, auth) { $scope.auth = auth; } 更新:根据关于falselys的评论,$scope.auth提供了一些值,也许最好将一些东西绑定到登录控制器。有什么想法吗 // Login
<span>Name is {{auth.profile.nickname}}</span>
// UserInfoCtrl.js
function UserInfoCtrl($scope, auth) {
$scope.auth = auth;
}
更新:根据关于falselys的评论,$scope.auth提供了一些值,也许最好将一些东西绑定到登录控制器。有什么想法吗
// 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.profile.nickname}
这样,如果定义了
auth
,您将只看到span
。最简单的方法是将其放在您的视图代码中:
<div ng-show='auth'></div>
改用这个:
if($scope.auth != null) {
$scope.loggedin
}
出于安全原因,我认为您的服务器应该只在用户登录时发送登录区域的内容 但是,如果出于某种原因,您希望在记录的区域执行此控制,则您有一些备选方案:
ng show=“auth”
-如果$scope.auth
无效,则不会显示。虽然你真的应该隐藏和显示从服务器,任何人都可以编辑HTML。不幸的是,它没有工作。似乎auth正在返回某些内容。也许我们可以将一些东西绑定到登录控制器。我已经更新了我的帖子。@Kode如果auth
返回了什么,那么再深入一点,检查与登录用户相关的其他值,可能是auth.profile
。只有您知道这是如何实现的:)使用$scope.loggedin=auth.profile;很好用!
if($scope.auth is not null {
$scope.loggedin
}
if($scope.auth != null) {
$scope.loggedin
}