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

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

问题描述

我工作的这个项目,并采用了棱角分明的框架。我是pretty初次使用这个js框架。在过去,我已经用纯JS和jQuery被仅工作。它是一种独特的市场网页设计师应用。

I am working on this project and using Angular framework. I am pretty new to using this js framework. In the past I have been only working with pure js and jQuery. It is kind of web designer application for a niche market.

由于用户可以在页面之间移动,而设计的,我想保持他正在的所有更改的会话。

As the user can move between pages while designing, I want to maintain a session of all the changes he is making.

现在如果我们的用户登录使用加载从DB数据会话。而当用户点击Save按钮,我们更新会话数据的数据库。有人告诉我,我可以保持角度会议类似的骨干。可能吗?如果是的话你能请直接给我一个教程怎么把所有我能找到的净是关于指令和用户界面。如果没有可能我有哪些选择。

Now if the user signs in we load the session using data from db. And when the user clicks on save button we update the db with the session data. Someone told me that I can maintain session in Angular similar to backbone. Is it possible? If yes can you please direct me to a tutorial coz all I could find on the net is about directives and ui. If not possible what are my 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例如,您可以如何使用:
<一href=\"http://plnkr.co/edit/Fg3uF4ukl5p88Z0AeQqU?p=$p$pview\">http://plnkr.co/edit/Fg3uF4ukl5p88Z0AeQqU?p=$p$pview

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

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

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