Answer the question
In order to leave comments, you need to log in
How to wrap $routeProvider?
There is a standard code:
angular.module("main", ["ngRoute"])
.config(RouterConfig);
function RouterConfig($routeProvider){
$routeProvider.when("/registration", {
templateUrl: "/features/registration/view.html",
controller: "RegistrationCtrl as reg"
});
//...
$routeProvider.otherwise({redirectTo: '/registration'});
}
function Router(){
this.features = [
"registration",
"timeLeft"
];
this.bindProvider = function($routeProvider){
for(var feature in this.features) {
$routeProvider.when("/" + feature, {
templateUrl: "/features/" + feature + "/view.html",
controller: feature + "Ctrl as " + feature
});
}
}
}
angular.module("main", ["ngRoute"])
.service("Router", Router)
.config(Router.bindProvider); //Не видит сервис
Answer the question
In order to leave comments, you need to log in
In general, you can’t reach $routeProvider
outside . config
Purely theoretically, you can try to use it decorator
.
Another option is to reduce the number of routes with something like this:
$routeProvider.when('/features/:feature*', {
templateUrl: function(urlParam){
return '/pages/' + urlParam.name + '.html';
},
controller: 'someController'
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question