在我的 Angular Controller 中,“未定义经过身份验证。我想仅在用户登录时显示更新按钮。我在用户登录时使用 ng-show,否则隐藏按钮。有人可以指导吗我到底做错了什么?
JavaScript
$scope.signIn = function () {
$rootScope.auth.$login('password', {
email: $scope.email,
password: $scope.password
}).then(function (user) {
Materialize.toast('Logged in successfully', 1000);
console.log(authenticated);
$scope.authenticated = true;
}, function (error) {
if (error = 'INVALID_EMAIL') {
Materialize.toast('Email invalid or not signed up — trying to sign you up!', 5000);
$scope.signUp();
} else if (error = 'INVALID_PASSWORD') {
console.log('wrong password!');
Materialize.toast('Invalid password', 1000);
} else {
console.log(error);
}
});
};
$scope.loggedin = false;
模板
<div ng-if="loggedin">
<a class="btn waves-effect waves-red" ng-href="/#/editWelcome/{{welcome._id}}">Update
</a>
</div>
最佳答案
有一个错字:
console.log(authenticated);
也许你想要这样:
console.log('authenticated');
或者也许:
console.log(user);
由于authenticated变量不存在,因此不会移动到下一行来设置$scope.authenticated = true;
关于javascript - "Authenticated"没有在我的 Angular Controller 函数中定义。我不确定我做错了什么。用尽所有选项。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32288106/