0

I'm using the $routeProvider and I want the route to load a different view depending on what is passed:

when('/tx/:txid', {
  templateUrl: '/views/tx/view.html'
}).

If txid matches a certain pattern, it should load one view. If it matches a different pattern, it should load a different view. Is this possible?

Shamoon
  • 41,293
  • 91
  • 306
  • 570
  • see this post. http://stackoverflow.com/questions/18131834/angularjs-regex-route-for-similar-url-to-load-different-controller-and-view – xspydr Jan 23 '14 at 20:40

2 Answers2

1

You can use function for dynamic views:

.when('/tx/:txid', {
    templateUrl: function(routeParams) {
        // return necessary view based on route params
        return '/views/tx/view.html'; 
    }
})

From documentation:

If templateUrl is a function, it will be called with the following parameters: {Array.} - route parameters extracted from the current $location.path() by applying the current route

dfsq
  • 191,768
  • 25
  • 236
  • 258
1

Have a look at dynamic templates.

when('/tx/:txid', 
    {   
      controller:ctrl, 
      templateUrl: function(params){ 
         // your logic here...
         return '/tx/diferentview/' + params.txid; 
      }
    }

This should do the trick.

hjgraca
  • 1,695
  • 1
  • 14
  • 29