在AngularJS形式之间的存储状态? [英] Store status between forms in AngularJS?

查看:169
本文介绍了在AngularJS形式之间的存储状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要尽量具体,我可以。这就是我要完成的:

I am going to try to be as specific as I can. This is what I am trying to accomplish:

我希望能够向用户展示,哪种鞋适合自己的需要。用户将显示4形成,一次一个。

I want to be able to show a User, which kind of shoes fit its needs. The user will be shown 4 forms, one at a time.

我的想法是显示一种形式,而一旦用户点击下一步,保存状态和显示下表。所有形式都被填满后,使用这些选择来获取API并将结果返回给用户。

My idea is to show a form, and once the user clicks 'Next', save that status and show the next form. After all forms have been filled, use those choices to fetch the API and return results to the User.

下面是我的问题:


  • 我应该在哪里存储他的选择的状态?曲奇饼?会议?

  • 如何将组织角度,以有所有这些形式的显示一个接一个的?我可以作为一个灵感使用任何资源?

顺便说一句,我使用Rails作为后端。

BTW, I am using Rails as a backend.

我根据我对这个教程的问题:的http:/ /$c$c.realcrowd.com/the-wonderful-wizard-of-angularjs/

I have based my question on this tutorial: http://code.realcrowd.com/the-wonderful-wizard-of-angularjs/

我看到他用对提交saveState和(),但我不知道在哪里该函数的定义。

I see that he uses saveState() on submit, but I am not sure where that function is defined.

推荐答案

由于应用程序是一个棱角分明的SPA,你可以使用一个角度服务来存储用户做出的选择的状态。这种状态会持续,直至用户明确地刷新浏览器(F5)。

Since the app is a angular SPA, you can use a angular service to store the state of the selection made by user. This state would persist until user explicitly refreshes the browser (F5).

创建像

angular.factory('shoeSelectionState',function() {
   var states=[{selection:{}},{selection:{}},{selection:{}},{selection:{}}];
   return states;
});

在您的控制器注入此服务,

In your controller inject this service,

angular.controller('MyController', function(shoeSelectionState) {
   $scope.states=shoeSelectionState;
});

和状态数组绑定到每个表单元素,像

and bind the states array to each form elements, something like

<输入类型='文本'NG-模式='状态[0] .selection.sizeNAME ='大小'>

如果你想坚持下去的页面刷新的数据尝试使用,因为它被自动清零的sessionStorage 而不是的localStorage 当用户关闭选项卡。上述服务可以做内容存储的持久性。

If you want to persist the data on page refresh try using sessionStorage instead of localStorage as it gets automatically cleared when user closes the tab. The service mentioned above can do the persistence of the content to storage.

这篇关于在AngularJS形式之间的存储状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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