title: AngularJS dynamic routing
body: <p>I currently have an AngularJS application with routing built in.
  It works and everything is ok.</p>
  
  <p>My app.js file looks like this:</p>
  
  <pre><code>angular.module('myapp', ['myapp.filters', 'myapp.services', 'myapp.directives']).
    config(['$routeProvider', function ($routeProvider) {
        $routeProvider.when('/', { templateUrl: '/pages/home.html', controller: HomeController });
        $routeProvider.when('/about', { templateUrl: '/pages/about.html', controller: AboutController });
        $routeProvider.when('/privacy', { templateUrl: '/pages/privacy.html', controller: AboutController });
        $routeProvider.when('/terms', { templateUrl: '/pages/terms.html', controller: AboutController });
        $routeProvider.otherwise({ redirectTo: '/' });
    }]);
  </code></pre>
  
  <p>My app has a CMS built in where you can copy and add new html files within the <strong>/pages</strong> directory.</p>
  
  <p>I would like to still go through the routing provider though even for the new dynamically added files.</p>
  
  <p>In an ideal world the routing pattern would be:</p>
  
  <p>$routeProvider.when('/<strong>pagename</strong>', { templateUrl: '/pages/<strong>pagename</strong>.html', controller: CMSController });</p>
  
  <p>So if my new page name was "contact.html" I would like angular to pick up "/contact" and redirect to "/pages/contact.html".</p>
  
  <p>Is this even possible?! and if so how?!</p>
  
  <p><strong>Update</strong></p>
  
  <p>I now have this in my routing config:</p>
  
  <pre><code>$routeProvider.when('/page/:name', { templateUrl: '/pages/home.html', controller: CMSController })
  </code></pre>
  
  <p>and in my CMSController:</p>
  
  <pre><code>function CMSController($scope, $route, $routeParams) {
      $route.current.templateUrl = '/pages/' + $routeParams.name + ".html";
      alert($route.current.templateUrl);
  }
  CMSController.$inject = ['$scope', '$route', '$routeParams'];
  </code></pre>
  
  <p>This sets the current templateUrl to the right value.</p>
  
  <p><em>However</em> I would now like to change the <em>ng-view</em> with the new templateUrl value. How is this accomplished?</p>