javascript - "Authenticated"没有在我的 Angular Controller 函数中定义。我不确定我做错了什么。用尽所有选项。

标签 javascript html angularjs authentication ng-show

在我的 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/

相关文章:

javascript - Chrome 扩展 js : Sharing functions between background. js 和 popup.js

Javascript 和 CSS 代码字面上出现在我的 HTML 页面上

javascript - TypeScript 是否具有 ES6 "Sets"的等效项

html - <a> 下载属性不再起作用

css - 让子 div 出现在绝对定位的父元素之上

Html <p> 标签动态扩展到另一个 div 旁边的父级

node.js - 防止使用 AngularJs 和 Node.js/Express 直接访问文件

javascript - Angular ng-class if else

javascript - 如何在页面加载时隐藏下拉列表?

javascript - Angular 中的滑动菜单无法通过 $provider 正常运行