如何基于angularjs中的条件重定向页面 [英] How to redirect a page based on condition in angularjs

查看:40
本文介绍了如何基于angularjs中的条件重定向页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在用户当时登录后根据条件重定向页面,"varView"标志将使用cookie或rootScope或任何其他选项具有一些值.之后,在配置中,当进行路由时,我必须检查标志,并且基于标志的值页面应获得重定向.

I want to redirect a page based on condition after logged in by user at that time "varView" flag will have some values using cookies or rootScope or any other option. After that, in config while doing routing i have to check the flag and based on flag's value page should get redirect.

这里的代码:

$routeProvider.when("/editTest/:testID",
{
  templateUrl: '/apps/templates/xyz/editTest.html',
               controller: 'EditTestController',
               resolve: {
    load: function (ShareData, $location) {
    var varView = 'tabPanelView'; // this value of varView will get loaded from login
    if (varView == 'tabPanelView') {
      $location.path('/editTestPageView.html');
    } else {
      $location.path('/editTestTabPanelView.html');
    }
    return ShareData.get('cEditTest');
  }
}
});

如果varView =='tabPanelView',则在editTestPageView.html页面上重定向,否则将其重定向到editTestTabPanelView.html.

If varView == 'tabPanelView' then redirect on editTestPageView.html page else redirect it to editTestTabPanelView.html.

实际上,我有一个带有两个差异的客户表格.视图(2个html文件),即一种具有可滚动的普通页面(具有部分的数量),另一种处于选项卡面板"视图模式,该模式将各部分划分为多个选项卡,而无法滚动.

Actually, i have a customer form with two diff. views (2 html files) i.e. one with normal page scrollable with number of sections and other one is in Tab Panel view mode which is sections divided in tabs without scrollable.

因此,页面查看设置位于用户的管理区域中.用户将选择所需的表单视图,并根据该视图打开页面.

So, the page view settings is on user's hand in admin area. User will choose which form view he wanted and according to that the page should get open.

推荐答案

最后,以

'<a href="#/editTest/{{model._id}}/' + getCookie(escape('cformview'))+ '" title="Edit Test"></a>'

在$ routeProvider中

And in $routeProvider

   $routeProvider.when("/editTest/:ID/:flagTab",
                        {                               
                             templateUrl: function (params) {
                                var flag = params.flagTab;                                    
                                if (flag == 'tabPanelView') {
                                    return '/apps/templates/editTest.html';
                                }
                                else {
                                    return '/apps/templates/editTestPageView.html';
                                }                                    
                            },
                            controller: 'EditTestController'
                        });

这篇关于如何基于angularjs中的条件重定向页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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