通过 Angular.js 维护会话 [英] Maintaining Session through Angular.js

查看:28
本文介绍了通过 Angular.js 维护会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 AngularJS 框架开展一个项目.我对使用这个框架很陌生;过去我只使用纯 JavaScript 和 jQuery.该项目是一种面向利基市场的网页设计师应用程序.

I am working a project using the AngularJS framework. I am pretty new to using this framework; in the past I have only worked with pure JavaScript and jQuery. The project is a kind of web designer application for a niche market.

当用户在设计时在页面之间移动时,我希望保持他们所做的所有更改的会话.

As the user moves between pages while designing I want to maintain a session of all the changes they are making.

现在,如果用户登录,我们将使用数据库中的数据加载会话.当用户点击保存按钮时,我们用会话数据更新数据库.有人告诉我,我可以在 Angular 中维护类似于主干的会话.这可能吗?如果是,能否请您指导我阅读不关注指令或 UI 的教程?如果这是不可能的,还有其他可行的选择吗?

Now if the user signs in we load the session using data from the database. When the user clicks on save button we update the database with the session data. Someone told me that I can maintain session in Angular similar to backbone. Is this possible? If yes, can you please direct me to a tutorial that does not focus on directives or UI? If this is not possible are there other viable options?

推荐答案

这里有一个片段给你:

app.factory('Session', function($http) {
  var Session = {
    data: {},
    saveSession: function() { /* save session data to db */ },
    updateSession: function() { 
      /* load data from db */
      $http.get('session.json').then(function(r) { return Session.data = r.data;});
    }
  };
  Session.updateSession();
  return Session; 
});

这是Plunker示例,您可以如何使用它:http://plnkr.co/edit/Fg3uF4ukl5p88Z0AeQqU?p=preview

Here is Plunker example how you can use that: http://plnkr.co/edit/Fg3uF4ukl5p88Z0AeQqU?p=preview

这篇关于通过 Angular.js 维护会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆