1

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.

Here's code:

$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');
  }
}
});

If varView == 'tabPanelView' then redirect on editTestPageView.html page else redirect it to editTestTabPanelView.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.

0

3 Answers 3

1

May be try to pass the "userpreference" as part of path For example:/editTest/:testID/:varView and inside routeProvider.

$routeProvider    
.when("/red/:testID/:varView", {        
    templateUrl: function(params) {         
    return params.varView == 'table'? "./pages/table.htm" : "./pages/scroll.htm";
  },controller  : 'aboutController'        
}) 

OR, can have template with in template inside HTML file using either,

    <div ng-switch-when="1">  OR <ng-include src="subPage"></ng-include>

You may take a look at below answer:

using $rootScope in templateUrl function

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, already i'm done with "userpreference" in the path. But looking for the better solution. However, we can't use $rootScope in this scenario.
1

Finally, ended with pass the parameters in url like

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

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'
                        });

Comments

0

You should be able to simply use the $window service. With an if condition you can use $window.open to go wherever you like. If that did not answer your question comment on why and I will try again. You will have to put the route in the open method.

2 Comments

$location provider is working fine, but the thing is here i have a parameter in edit mode, so when page is redirected the edit id is not getting passed in url. I don't think so we can inject services in config section as we can inject only providers and constants.
ahhh, ok, I see... you can inject a constant I believe. Perhaps that would work, I see your issue now.. you are in the config section and you can't inject a service. Let me ponder on it..

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.