I find unsatisfactory solve, where templateUrl define at routeProvider, and at controller it redefine. But it is one excess request. (PS: I have my templates at any folder and I have hash-routes with name of this templates, how can I do this(render my template at current hash) correctly?)
For example this code render my index.html template at ng-view tag:
angular.module('amiu', [])
.config(function($routeProvider){
$routeProvider
.when('/index/', {templateUrl:'partitials/index.html'})
})
But I want to do that:
angular.module('amiu', [])
.config(function($routeProvider, $routeParams){
$routeProvider
.when('/:page/', {templateUrl:'template/'+$routeParams.page+'.html'})
.otherwise({redirectTo:"/"})
})
How can I do that?
I'd propose something else. let the $routeProvider "normal" and use the controller to set the path to a ng-include in your template :
$routeProvider
.when('/page/:page', {templateUrl:'template/page.html',
controller:"PageController"});
in the PageController , inject $routeParams , and use it to modify the url of an include in your template.
$scope.include_url = $routeParams.page ;
finaly in the page.html template , wire things up :
<div data-ng-include="'template/page-'+include_url+'.html"></div>
it has not been tested , i'm open to modifications and suggestions.