为标签和表单提交的按需加载最好的方法 [英] Best approach for On demand loading of tabs and form submission

查看:203
本文介绍了为标签和表单提交的按需加载最好的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发使用angularJS的应用程序。此应用程序有大约5个选项卡,这主要是一种形式,一个单一的所有标签提交选项。(类似于员工数据维护)的形式加载与用户的数据时,页面被加载和用户可以编辑和重新提交表单

I am developing an app using angularJS. This application has about 5 tabs and this is mainly a form and a single submit option for all tabs.(similar to employee data maintenance) The form is loaded with data of the user when the page gets loaded and user can edit and resubmit the form.

由于加载在初始页面加载会影响页面的加载时间全部5个标签,所以我计划在内容和API按需加载使用。

Since loading all the 5 tabs in the initial page load will effect the load time of the page , so i am planning to use on demand loading of contents and API.

1的方法:
有一件事我能做的就是在加载初始加载仅1选项卡,并加载基于点击的页面,并使用其他选项卡NG-包括包括局部视图。所以在最终用户可以提交表单和客户端验证可以easily.In这种情况下,页面完成将所有激活的标签的DOM元素。

1st approach: One thing i can do is loading only 1st tab on initial load and load the other tabs based on click on the tab and using ng-include to include partial views. So in the end user can submit the form and client side validation can be done easily.In this case page will have DOM elements of all activated tabs.

第二个办法:使用的路由(我没有太多熟悉)。但是从我的理解这个逻辑将取代当用户切换标签不像第一次的做法标签的DOM。所以,有必要利用服务或一些其它技术来保存数据。但我想标签切换时,激活的标签,甚至保留previous的DOM。所以,能不能做到?

2nd approach: By using routing (i am not much familiar with this). But from my understanding this logic will replace the DOM of a tab when user switches tab unlike 1st approach. So there is a need of using service or some other technique to save the data. But i want to retain the DOM of previous active tab even when tab is switched. So can it be done?

最后,还有什么是二上方或中最好的方法是什么其他好的技术来达到同样的?

Finally, What is the best approach among above two OR is there any other good techniques to achieve same?

推荐答案

我认为选择2将工作最适合你。 AngularUI路由器( https://github.com/angular-ui/ui-router )将有助于这一标准的NG-路由器之上。

I think Option 2 would work best for you. AngularUI router (https://github.com/angular-ui/ui-router) would help with this above the standard ng-router.

而不是保存标签交换机之间的DOM,你可以只当你切换标签保存数据并重新绑定。

Rather than save the DOM between tab switches, you could just save the data and re-bind when you switch tabs.

这篇关于为标签和表单提交的按需加载最好的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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