小编Sud*_*hir的帖子

如何使用angularjs注销后清除本地存储

Html代码

<div><a href="#/logout"><h2>Log Out</h2></a></div>
Run Code Online (Sandbox Code Playgroud)

我的路由

 app.config([ '$routeProvider', function($routeProvider) {

    $routeProvider.when('/', {
        templateUrl : 'app/components/login/Login.html',
        controller : 'loginCtrl'

    }).when('/register/', {
        templateUrl : 'app/components/register/register.html',
        controller : 'registerController'
    }).when('/welcome/', {
        templateUrl : 'app/components/welcome/welcome.html',
        controller : 'welcomeController'
    }).when('/home', {
        templateUrl : 'app/components/home/home.html',
        controller : 'homeController'
    }).when('/homeView', {
        templateUrl : 'app/components/home/homeView.html',
        controller : 'homeController'
    }).when('/graph', {
        templateUrl : 'app/components/home/graphView.html',
        controller : 'LineCtrl'
    }).when('/logout', {
        templateUrl : 'app/components/login/Login.html',
        controller : 'logoutCtrl'
    }).otherwise({
        redirectTo : "/"
    });
} ]);
Run Code Online (Sandbox Code Playgroud)

注销控制器

app.controller('LogoutController',function($location,$scope){
        $location.path('/');
});
Run Code Online (Sandbox Code Playgroud)

它工作正常,退出后它进入登录页面,如果我按回按钮也不会重定向到最后一页,但我认为这不是正确的方式我工作,我没有清除本地存储,而退出,我卡住了如何通过注销清除本地存储值,请帮助我,我是angularjs的新手

登录控制器,其值设置为localstorage

 $scope.login = …
Run Code Online (Sandbox Code Playgroud)

angularjs

12
推荐指数
1
解决办法
3万
查看次数

将数组显示为分页视图

我正在尝试使用 Angular PPT 视图页面来显示对象数组ngFor。为此,我准备了一个临时对象,它工作正常,我能够将其显示为页面。

临时对象:

let data = [
      {
        "page": "page1",
        "data": [
          {
            "id": "1",
            "content": "abc",
            "checked": true
          },
          {
            "id": "2",
            "content": "xyz",
            "checked": true
          }
        ]
      },
      {
        "page": "page2",
        "data": [
          {
            "id": "3",
            "content": "abc",
            "checked": true
          },
          {
            "id": "4",
            "content": "xyz",
            "checked": true
          }
        ]
      }
    ]
Run Code Online (Sandbox Code Playgroud)

但是,使用我的原始数组,我无法转换为相同的格式

原始数组

[
  {
    "id": 1,
    "content": "abc"
  },
   {
    "id": 2,
    "content": "xyz"
  },
   {
    "id": 3,
    "content": "xyz"
  },
   { …
Run Code Online (Sandbox Code Playgroud)

javascript angular

2
推荐指数
1
解决办法
218
查看次数

标签 统计

angular ×1

angularjs ×1

javascript ×1