Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/235.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用ngCookies进行登录_Php_Angularjs - Fatal编程技术网

Php 使用ngCookies进行登录

Php 使用ngCookies进行登录,php,angularjs,Php,Angularjs,我是英语初学者。我想使用ngCookie登录。我正在使用ajax从PHP后端获取用户信息,如果我有用户名,将显示一个注销按钮。这是我的密码: $http({ method:'POST', url:'login.php', data:$.param(vm.formData), headers : { 'Content-Type': 'application/x-www-form-urlencoded' } }).then(Success); function Success(re

我是英语初学者。我想使用
ngCookie
登录。我正在使用ajax从PHP后端获取用户信息,如果我有用户名,将显示一个注销按钮。这是我的密码:

$http({
  method:'POST',
  url:'login.php',
  data:$.param(vm.formData),
  headers : { 'Content-Type': 'application/x-www-form-urlencoded' }
}).then(Success);

function Success(response) {
  $cookies.get('username') = response.data.username;
  $cookies.put('username','username');
}
这是我的html

<div ng-show="username">
    <li><a href="">Hello {{username}}</a></li>
    <li><a href="">Log out</a></li>
</div>

  • 错误:

    angular.js:12520 ReferenceError:赋值中的左侧无效


    这可能就是错误所在

    $cookies.get('username') = response.data.username;
    
    如果要为用户名赋值,请尝试此操作

    // Setting a cookie for the user
    $cookies.put('currentUser', response.data.username);
    // Retrieving a cookie for the user
    var currentUser = $cookies.get('currentUser');
    
    您可以尝试使用注销按钮

    <body ng-controller="MainCtrl">
    <button ng-if="user">Log Out</button>
    </body>
    
    angular.controller("MainCtrl",function($scope,$cookies){
    $scope.user = $cookies.get("currentUser");
    });
    
    
    注销
    角度控制器(“MainCtrl”,函数($scope,$cookies){
    $scope.user=$cookies.get(“当前用户”);
    });
    
    谢谢你。它工作,但注销按钮不显示。我如何修复它?如果ng show etcDid需要一些重新格式化和排版修复,您将希望它位于您的$scope中。